使用 LaTeX,如何将文本直接置于右对齐标题下方?也许我迄今为止的尝试可以更好地解释这一点:
\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}
问题是minipage
需要一个宽度参数,因此,我让第二行完美居中的唯一方法是(提前)猜测标题渲染后的确切宽度。有没有更好的方法?
答案1
\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}
答案2
David 的tabular
解决方案非常有效,但我经常求助于使用\makebox
来创建一个所需宽度的框,并将文本对齐在该“框”内。下面我展示了如何在与 一样宽的框内c
输入、r
向右和向左对齐文本:l
\widthof{\huge Another Heading}
笔记:
- 宏
\widthof
来自包裹calc
。
代码:
\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}
答案3
摞起它。
\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}