14

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 “<code>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 “<code>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).

4

4 回答 4

15

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

% 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}
于 2010-03-31T14:53:51.943 回答
7

1pt 高度的水平尺,升高 1.5pt。

Hello \leaders\vrule height 2.5pt depth -1.5pt \hfill \null
于 2010-03-31T14:58:35.753 回答
0

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

于 2015-04-13T04:23:02.280 回答
0

有一个名为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}

这将产生

强调

出于您的好奇心,normalem包 ulem 的选项可防止 ulem 使用\emor产生额外的下划线\emph

于 2019-12-20T20:36:55.197 回答