0

Please see my questions in the following MWE. Thank you.

\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}
5
  • why have you \hrule, \vrule, \vskipin a latex document? a latex \rulecommand will indent like paragraph text, if you use tex primitives then you break latex conventions. \parand leftskipshould also not be used (setting leftskip directly will break latex's list environments) Jan 31, 2022 at 15:20
  • because \hrule begins a new paragragh, and it can work with \vrule to get a effect of simple table, but \rule can not.
    – lyl
    Jan 31, 2022 at 15:27
  • no you have that backwards: \rule will start a new paragraph, \hruledoes not start a paragraph it directly adds a rule in vertical mode, leavling tex in vertical mode. I thought that behaviour was what you were asking to avoid. otherwise I do not understand what you mean by "does not come with the paragraph" Jan 31, 2022 at 15:29
  • You could put it into a \parbox, but then you would be in hmode and might as well use \rule. Jan 31, 2022 at 15:59
  • Anyone can help me with the \rule version for the two examples i give?
    – lyl
    Feb 1, 2022 at 2:16

1 Answer 1

2

There are no cases where such TeX primitves should ever appear in a document, but \hruledoes not start a paragraph so is unaffected by \parindentor \leftskip You can shift it right if you must, also adding negative kerning by the default rule width avoids the "notch" at the corner.

enter image description here

\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}

(A similar negative kern would fix the second question too if I understand it correctly.)

6
  • Many thanks @David Carlisle for your solution! And, you said "also adding negative kerning by the default rule width avoids the "notch" at the corner." How to make the default width to be other value, 0.8pt for example? And what is the purpose for \offinterlineskip?
    – lyl
    Feb 1, 2022 at 2:19
  • the default width is fixed in Tex @lyt Feb 1, 2022 at 7:00
  • I add some text before \moveright in your code, "something \moveright\leftskip\vbox{\hrule width 0.3\textwidth}". This fails to work. Why?
    – lyl
    Feb 2, 2022 at 8:07
  • @lyl that is to be expected. Sorry if you choose to use unsupported tex primitives in a latex document you have to expect things not to work in any natural way, latex constructs are designed to work together. You can only use \moveright in vertical mode, Feb 2, 2022 at 8:59
  • Would you please help me with the LaTex version of my example?
    – lyl
    Feb 2, 2022 at 10:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .