Posts

Showing posts with the label Center

Center Plot Title In Ggplot2

Image
Answer : From the release news of ggplot 2.2.0 : "The main plot title is now left-aligned to better work better with a subtitle". See also the plot.title argument in ?theme : "left-aligned by default". As pointed out by @J_F, you may add theme(plot.title = element_text(hjust = 0.5)) to center the title. ggplot() + ggtitle("Default in 2.2.0 is left-aligned") ggplot() + ggtitle("Use theme(plot.title = element_text(hjust = 0.5)) to center") + theme(plot.title = element_text(hjust = 0.5)) As stated in the answer by Henrik, titles are left-aligned by default starting with ggplot 2.2.0. Titles can be centered by adding this to the plot: theme(plot.title = element_text(hjust = 0.5)) However, if you create many plots, it may be tedious to add this line everywhere. One could then also change the default behaviour of ggplot with theme_update(plot.title = element_text(hjust = 0.5)) Once you have run this line, all plots created...

Center Button Under Form In Bootstrap

Answer : Remove that <p> tag and add the button inside a <div class="form-actions"> like this: <div class="form-actions"> <button type="submit" class="btn">Confirm</button> </div> an then augment the CSS class with: .form-actions { margin: 0; background-color: transparent; text-align: center; } Here's a JS Bin demo: http://jsbin.com/ijozof/2 Look for form-actions at the Bootstrap doc here: http://twitter.github.io/bootstrap/base-css.html#buttons With Bootstrap 3, you can use the 'text-center' styling attribute. <div class="col-md-3 text-center"> <button id="button" name="button" class="btn btn-primary">Press Me!</button> </div> If you're using Bootstrap 4 , try this: <div class="mx-auto text-center"> <button id="button" name="button" class=...

Centering Floating Divs Within Another Div

Answer : First, remove the float attribute on the inner div s. Then, put text-align: center on the main outer div . And for the inner div s, use display: inline-block . Might also be wise to give them explicit widths too. <div style="margin: auto 1.5em; display: inline-block;"> <img title="Nadia Bjorlin" alt="Nadia Bjorlin" src="headshot.nadia.png"/> <br/> Nadia Bjorlin </div> With Flexbox you can easily horizontally (and vertically) center floated children inside a div. So if you have simple markup like so: <div class="wpr"> <span></span> <span></span> <span></span> <span></span> <span></span> </div> with CSS: .wpr { width: 400px; height: 100px; background: pink; padding: 10px 30px; } .wpr span { width: 50px; height: 50px; background: green; float: left; /* **chi...

Android Relative Layout Center Vertical With Margin

Answer : Try this: Try to use RelativeLayout which can easily done your requirement using weight : <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_vertical"> <TextView android:id="@id/dummy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_centerHorizontal="true" /> <TextView android:layout_below="@id/dummy" android:layout_marginTop="10dp" android:text="This is TextView" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </RelativeLayout> Try to use LinearLayout which can easily done your requirement using weight : <LinearLayout xmlns:and...