有没有办法知道段落使用的宽度?在下面的代码中,我想将行调整为比文本稍大一点“地点:彩虹之上某处”。
\documentclass[12pt]{article}
\usepackage[showframe]{geometry}
\begin{document}
\setlength{\parindent}{0pt}
\begin{center}
\rule[0.4ex]{\linewidth}{0.2ex}
DS: Probability \& Geometry
Location: Somewhere over the rainbow
\rule[0.4ex]{\linewidth}{0.2ex}
\end{center}
Bla, bla, bla, bla, bla, bla, ...
\end{document}
答案1
像这样?
\documentclass[12pt]{article}
\usepackage[showframe]{geometry}
\usepackage{booktabs}
\begin{document}
\begin{center}
\begin{tabular}{c}
\midrule
DS: Probability \& Geometry \\
Location: Somewhere over the rainbow \\
\midrule
\end{tabular}
\end{center}
Bla, bla, bla, bla, bla, bla, ...
\end{document}
编辑:
如果您想改变midrule
厚度,您可以添加厚度选项,例如\midrule[3pt]
。对于顶部规则,您也可以使用\toprule
或\toprule[2pt]
。有关更多详细信息,请参阅包的文档booktabs
。
规则比\tabcolsep
表格单元格两侧的文本长。其默认大小为6pt
,但您可以使用更改大小\setlength\tabcolsep{<desired length>}
。以下是一个例子:
\documentclass[12pt]{article}
\usepackage[showframe]{geometry}
\usepackage{booktabs}
\begin{document}
\begin{center}
\setlength\tabcolsep{12pt}
\begin{tabular}{c}
\toprule[2pt]
DS: Probability \& Geometry \\
Location: Somewhere over the rainbow \\
\midrule[3pt]
\end{tabular}
\end{center}
Bla, bla, bla, bla, bla, bla, ...
\end{document}
如果你想设置一个超调系数,比如 20%,
\documentclass[12pt]{article}
\usepackage[showframe]{geometry}
\usepackage{booktabs}
\begin{document}
\begin{center}
\begin{tabular}{c}
\toprule[2pt]
\makebox[1.20\width]{% 20% longer rules
\begin{tabular}{@{}c@{}}
DS: Probability \& Geometry \\
Location: Somewhere over the rainbow
\end{tabular}%
}\\
\midrule[3pt]
\end{tabular}
\end{center}
Bla, bla, bla, bla, bla, bla, ...
\end{document}
答案2
您还可以使用\widthof{}
usepackage calc,例如:\rule[0.4ex]{\widthof{Location: Somewhere over the rainbow}}{0.2ex}