我想插入一条规则而不影响文本格式。以下是我尝试实现的结果:
源代码是:
\documentclass[a4paper,12pt]{article}
\usepackage{parskip}
\begin{document}
The \texttt{parbox} command definition:
\begin{verbatim*}
\parbox[vertical_alignment][height][inner_alignment]{width}{text}
\end{verbatim*}
\vfill
Some \texttt{parbox} examples:
\quad\fbox{\parbox[b][5cm][t]{2.5cm}{This box is aligned at the bottom and the text at the top. The height is 5cm and width 2.5cm}}
\quad\fbox{\parbox{1.5cm}{center-aligned parbox}}
\quad\fbox{\parbox[t]{2cm}{another parbox aligned at its top line}}
\vfill
\end{document}
红线必须是文本基线宽度为:textwidth
。我尝试使用:
\rule{\textwidth}{0.1pt}
但它移动了所有文本和段落框。
答案1
\llap
您可以使用纯 TeX 宏在段落末尾添加该行:
\vfill
Some \texttt{parbox} examples:
\quad\fbox{\parbox[b][5cm][t]{2.5cm}{This box is aligned at the bottom and the t
\quad\fbox{\parbox{1.5cm}{center-aligned parbox}}
\quad\fbox{\parbox[t]{2cm}{another parbox aligned at its top line}}%
\hfill\llap{\textcolor{red}{\vrule height.3pt depth.3pt width\hsize}}\par
\vfill
由于绘图是在同一段落行,所以不影响排版。
答案2
在段落开头使用零宽度框,其中包含延伸到右边距的规则。
\documentclass[a4paper,12pt]{article}
\usepackage{geometry} % less generous margins
\usepackage{parskip}
\usepackage{xcolor}
\newcommand{\showbaseline}{\makebox[0pt][l]{%
\color{red!80}%
\vrule height 0.2pt depth 0.2pt width \linewidth
}}
\begin{document}
The \texttt{parbox} command definition:
\begin{verbatim*}
\parbox[vertical_alignment][height][inner_alignment]{width}{text}
\end{verbatim*}
\bigskip
\showbaseline Some \texttt{parbox} examples:
\quad\fbox{\parbox[b][5cm][t]{2.5cm}{\raggedright This box is aligned at the bottom and
the text at the top. The height is 5cm and width 2.5cm}}%
\quad\fbox{\parbox{1.5cm}{\raggedright center-aligned parbox here}}%
\quad\fbox{\parbox[t]{2cm}{\raggedright another parbox aligned at its top line}}
\end{document}