答案1
答案2
这里,我采用了 的定义\hrulefill
,并为 添加了高度/宽度/深度规范\hrule
,使其可以自定义(我称之为\myrulefill
)。此外,通过避免之前建议的\raisebox
,文本位于基线上。
\documentclass{article}
\def\dotfill#1{\cleaders\hbox to #1{.}\hfill}
\makeatletter
\def\myrulefill{\leavevmode\leaders\hrule height .7ex width 1ex depth -0.6ex\hfill\kern\z@}
\makeatother
\begin{document}
\noindent\myrulefill Short Text\myrulefill\par
\noindent\myrulefill This is Longer Text\myrulefill
\noindent\myrulefill What you see is very long text\myrulefill
\makeatletter
\def\myrulefill{\leavevmode\leaders\hrule height .9ex width 1ex depth -0.2ex\hfill\kern\z@}
\makeatother
\noindent\myrulefill Short Text\myrulefill\par
\noindent\myrulefill This is Longer Text\myrulefill
\noindent\myrulefill What you see is very long text\myrulefill
\end{document}
答案3
\documentclass[a4paper,11pt]{article}
\usepackage{array}
\usepackage{ragged2e}
%% Define a new command as Steven B. Segletes suggested:
%% Use the length \rlength to have a default width.
\newlength{\rlength}\setlength{\rlength}{5cm}
\newcommand{\ruletext}[2][\rlength]{%
\noindent%
\parbox{#1}{%
\noindent\hrulefill\raisebox{-.3\ht\strutbox}{#2}\hrulefill\par}%
}
\begin{document}
\ruletext{Foo}
\ruletext{Bar Baz}
%% Change the width of the box.
\ruletext[3cm]{Hello World}
\end{document}
结果是