
使用 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
大衛的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}