Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

With LaTeX, how do I center text directly beneath a right-aligned heading? Maybe it's better explained with my attempt so far:

\documentclass{article}
\usepackage[ hmargin = 1in, vmargin = 1in ]{geometry}
\setlength{\parindent}{0pt}
\usepackage{showframe}
\begin{document}

\begin{minipage}{.6\linewidth}\huge Some Heading\end{minipage}
\hfill
\begin{minipage}{.33\linewidth}
    \raggedleft {\huge Another Heading} \\
    \centering  \today
\end{minipage}

\end{document}

The problem is that minipage requires a width argument, so the only way I can get the second line perfectly centered is if I guess (ahead of time) the exact width that the heading will be after it's rendered. Is there a better way?

share|improve this question

3 Answers 3

up vote 4 down vote accepted
\documentclass{article}
\usepackage[ hmargin = 1in, vmargin = 1in ]{geometry}
\setlength{\parindent}{0pt}
\usepackage{showframe}
\begin{document}

\begin{minipage}[t]{.6\linewidth}\huge Some Heading\end{minipage}
\hfill
\begin{tabular}[t]{@{}c@{}}
\huge Another Heading \\
\today
\end{tabular}

\end{document}
share|improve this answer
    
+1 it never occurred to me that tabular doesn't require a width... nice and simple –  Michael Kropat May 9 at 21:34
    
@MichaelKropat tabular is used in this way in many of the standard class frontmatter elements eg article sets each \author as a tabular for this reason. –  David Carlisle May 9 at 21:47

Stack it.

\documentclass{article}
\usepackage[ hmargin = 1in, vmargin = 1in ]{geometry}
\setlength{\parindent}{0pt}
\usepackage{showframe}
\usepackage{stackengine}
\begin{document}
{\huge Some Heading}
\hfill
\stackunder[2pt]{\huge Another Heading}{\today}
\end{document}

enter image description here

share|improve this answer
    
+1 your package looks really powerful –  Michael Kropat May 9 at 21:31
    
@MichaelKropat Thanks for taking the time to look. If you need those same features with tabbing, the tabstackengine package provides a wrapper around stackengine, which provides tabbing & columns. –  Steven B. Segletes May 9 at 21:33

David's tabular solution works great, but I often resort to using \makebox to create a box of the desired width and align the text within that "box". Below I show how to center, right, and left align the text within a box which is as wide as the\widthof{\huge Another Heading}:

enter image description here

Notes:

Code:

\documentclass{article}
\usepackage[ hmargin = 1in, vmargin = 1in ]{geometry}
\setlength{\parindent}{0pt}
\usepackage{showframe}
\usepackage{calc}

\begin{document}

\begin{minipage}{.3\linewidth}\huge Some Heading\end{minipage}
\hfill
\begin{minipage}{.4\linewidth}
    \raggedleft {\huge Another Heading} \\
    \makebox[\widthof{\huge Another Heading}][c]{\today} \\
    \makebox[\widthof{\huge Another Heading}][r]{\today} \\
    \makebox[\widthof{\huge Another Heading}][l]{\today}
\end{minipage}

\end{document}
share|improve this answer
    
+1 wow, with the \widthof macro, you could roll your own solution to any number of alignment challenges –  Michael Kropat May 9 at 23:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.