如何控制 \hrule 的水平位置

如何控制 \hrule 的水平位置

请参阅以下 MWE 中的问题。谢谢。

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage{geometry}
\geometry{showframe}
\geometry{left=1cm,right=1cm,top=1cm,bottom=1cm}

\begin{document}
\parindent0pt \leftskip4cm
Example 1:\par
\hrule width 0.3\textwidth%
\vrule\makebox[0.3\textwidth]{The first line gy}\vrule
\hrule width 0.3\textwidth%
\vskip 1em
In the above example, the rule by \verb|\hrule| does not come with the paragraph.\\
Question: how to move the rule with the paragraph?\par\vskip 2em

\parindent0pt \leftskip0cm
Example 2:\par
\hrule width 0.3\textwidth%
\vrule\makebox[0.3\textwidth]{The first line gy}\vrule
\hrule width 0.3\textwidth
\hrule width 0pt height 0pt
\vrule\makebox[0.3\textwidth]{The second line qf}\vrule
\hrule width 0pt height 0pt
\vrule\parbox{0.3\textwidth}{The third line\par The fourth line qy}\vrule%
\hrule width 0.3\textwidth
\vskip 1em
Question: How to eliminate the clearance between horizontal and vertical rules on the right side?
\end{document}

答案1

此类 TeX 基元绝对不应该出现在文档中,但\hrule由于它们不会成为段落的开头,所以不会受到影响,\parindent或者\leftskip如果必须的话,您可以将其向右移动,同时通过默认规则宽度添加负字距可以避免角落出现“缺口”。

在此处输入图片描述

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage{geometry}
\geometry{showframe}
\geometry{left=1cm,right=1cm,top=1cm,bottom=1cm}

\begin{document}
\parindent0pt \leftskip4cm
Example 1:\par
\moveright\leftskip\vbox{\hrule width 0.3\textwidth}%
\offinterlineskip
\vrule\kern-.4pt\makebox[0.3\textwidth]{The first line gy}\kern-.4pt\vrule
\par
\offinterlineskip
\moveright\leftskip\vbox{\hrule width 0.3\textwidth}%
\vskip 1em
In the above example, the rule by \verb|\hrule| does not come with the paragraph.\\
Question: how to move the rule with the paragraph?\par\vskip 2em

\end{document}

(如果我理解正确的话,类似的负字距也可以解决第二个问题。)

相关内容