我想要一条水平线从文本末尾延伸到右边距。到目前为止,我找到了\hrulefill
和\leaders\hrule\hfill
,但它们绘制的线与文本的基线齐平——我怎样才能让它垂直居中?
答案1
\documentclass{article}
\usepackage{xhfill}
\begin{document}
Here is some text\xfill{1pt} \par
Here is some text\xfill{8pt} \par
Here is some text\xhrulefill{blue}{2pt}\par
Here is some text\xhrulefill{cyan}{1ex}\par
Here is some text\xrfill[0ex]{1ex}[red] \par
\end{document}
答案2
您可以定义类似于的命令\hrulefill
,但改变所用规则的高度和深度:
\documentclass{article}
\def\Vhrulefill{\leavevmode\leaders\hrule height 0.7ex depth \dimexpr0.4pt-0.7ex\hfill\kern0pt}
\begin{document}
\noindent text\hrulefill
\noindent text\Vhrulefill
\end{document}
答案3
\documentclass[a4paper]{article}
\newcommand\filltoend{\leavevmode{\unskip
\leaders\hrule height.5ex depth\dimexpr-.5ex+0.4pt\hfill\hbox{}%
\parfillskip=0pt\endgraf}}
\newenvironment{filllines}
{\par\let\par\filltoend}
{\par}
\usepackage{lipsum}
\begin{document}
A paragraph outside the environment can be ended with the
command \verb|\filltoend| like this one.\filltoend
\begin{filllines}
In this environment all paragraphs will be ended with a line.
As it's shown here.
\end{filllines}
\end{document}
相对于其他建议的解决方案,这种方法的优势在于,当段落恰好在右边距结束时,它不会出现任何问题。然而,出于技术原因,当列表环境在里面时,它将不起作用filllines
(列表环境根据原始命令重新定义\par
,不考虑其当前含义),但\filltoend
可以工作。
如果无论如何都需要规则,请更改规范
\leaders\hrule height.5ex depth\dimexpr-.5ex+0.4pt\hfill
进入
\leaders\hrule height.5ex depth\dimexpr-.5ex+0.4pt\hskip1em plus 1fill
这将绘制一条宽度至少为 1em 的规则。
答案4
以下生成高度(默认为)和厚度(默认为)\centerline[<height>][<thickness>]
的规则。与传统的 相比,水平对齐并不完全理想,但这也许不是问题。<height>
0.5ex
<thickness>
0.4pt
\hrulefill
\documentclass{article}
\usepackage{linegoal}% http://ctan.org/pkg/linegoal
\usepackage{xparse}% http://ctan.org/pkg/xparse
\NewDocumentCommand{\centerrule}{O{0.5ex} O{0.4pt}}{%
\leavevmode\rule[#1]{\linegoal}{#2}}%
}
\begin{document}
Here is some text\centerrule \par
Here is some text\centerrule[0pt] \par
Here is some text\centerrule[0.5ex][1pt] \par
Here is some text\centerrule[0pt][2pt]
\end{document}
接口由xparse
包裹,而生产线末端的估计是使用\linegoal
(来自linegoal
包裹)。至少需要2次编译。