LaTeX \rule 填充该行

发布于 2024-08-27 23:35:28 字数 419 浏览 8 评论 0原文

为什么以下命令不会生成填充行尾之前的空间的水平线?

Hello \rule[0.5em]{\fill}{1pt}

据我了解,这应该打印文本“Hello”,后跟一条延伸到行尾的水平线,类似于宏 \hfill ,它实际上是相当于\hspace\fill。 – 但实际上,这个命令只是产生文本“Hello”,没有规则。

我知道效果可以由 \hrulefill 产生,但不能在这里使用,因为我想要一个 raised 规则和 \hrulefill不能与 \raisebox 一起使用,并且我希望我的规则悬挂在基线之上(最好位于该行的中间)。

Why does the following command not produce a horizontal rule filling the space until the end of the line?

Hello \rule[0.5em]{\fill}{1pt}

It is my understanding that this should print the text “Hello” followed by a horizontal rule that extends until the end of the line, analogously to the macro \hfill which is effectively equivalent to \hspace\fill. – But in effect, this command just produces the text “Hello”, no rule.

I am aware that the effect can be produced by \hrulefill but it can’t be used here because I want a raised rule and \hrulefill doesn’t work together with \raisebox and I want my rule to hang above the baseline (at best in the middle of the line).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

山色无中 2024-09-03 23:35:28

对于为什么您提供的命令不起作用,我没有令人满意的答案,但我可以提供有效的解决方法。将其放入

% Raised Rule Command:
%  Arg 1 (Optional) - How high to raise the rule
%  Arg 2            - Thickness of the rule
\newcommand{\raisedrule}[2][0em]{\leaders\hbox{\rule[#1]{1pt}{#2}}\hfill}

文档的前言中,然后您就可以完成您希望的事情:

Hello \raisedrule[0.5em]{1pt}

I don't have a satisfying answer as to why the command you presented doesn't work, but I can offer an effective workaround. Put

% Raised Rule Command:
%  Arg 1 (Optional) - How high to raise the rule
%  Arg 2            - Thickness of the rule
\newcommand{\raisedrule}[2][0em]{\leaders\hbox{\rule[#1]{1pt}{#2}}\hfill}

into your document's preface, and then you can accomplish what you were hoping to with:

Hello \raisedrule[0.5em]{1pt}
街角迷惘 2024-09-03 23:35:28

水平尺高度为 1pt,并升高 1.5pt。

Hello \leaders\vrule height 2.5pt depth -1.5pt \hfill \null

The horizontal rule of 1pt height and raised by 1.5pt.

Hello \leaders\vrule height 2.5pt depth -1.5pt \hfill \null
半透明的墙 2024-09-03 23:35:28

有一个名为 ulem 的包,它

% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = xelatex
\documentclass{article}
\usepackage[normalem]{ulem}

\begin{document}
normal text \uline{\textit{underline text}\hfill}
\end{document}

会生成

underline

为了满足您的好奇心, ulem 包的选项 normalem 可以防止 ulem 使用 \em\emph 生成额外的下划线。

There is a package called ulem which does this

% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = xelatex
\documentclass{article}
\usepackage[normalem]{ulem}

\begin{document}
normal text \uline{\textit{underline text}\hfill}
\end{document}

which will produce

underline

For your curiosity, the option normalem for package ulem prevents ulem to produce extra underline with \em or \emph.

永不分离 2024-09-03 23:35:28

您可以使用命令 \hrulefill 来完成此操作
请参阅http://en.wikibooks.org/wiki/LaTeX/Lengths#Fill_the_rest_of_the_line

You can do this with the command \hrulefill
see http://en.wikibooks.org/wiki/LaTeX/Lengths#Fill_the_rest_of_the_line

浅唱々樱花落 2024-09-03 23:35:28

% 我做到了!
%

\documentclass{article}
\usepackage[normalem]{ulem}

\begin{document}
\uline{Some text \hfill\phantom{.}}
\end{document}

% I did it!
%

\documentclass{article}
\usepackage[normalem]{ulem}

\begin{document}
\uline{Some text \hfill\phantom{.}}
\end{document}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文