# Center text directly beneath a right-aligned heading

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?

-

## 3 Answers

\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}

-
+1 it never occurred to me that tabular doesn't require a width... nice and simple – Michael Kropat May 9 '14 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 '14 at 21:47

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}:

## 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}

-
+1 wow, with the \widthof macro, you could roll your own solution to any number of alignment challenges – Michael Kropat May 9 '14 at 23:00

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}


-
+1 your package looks really powerful – Michael Kropat May 9 '14 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 '14 at 21:33