2

I would like to insert a rule without affecting the text format. Here is what I attempt to obtain:

Desired output

The source code is:

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

The red line has to be the text baseline with width: textwidth. I tried to use:

\rule{\textwidth}{0.1pt}

But it moved all the text and paragraph boxes.

2 Answers 2

5

You can add the line at the end of the paragraph using \llap plain TeX macro:

\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

It doesn't affect the typesetting because the drawing is at the same paragraph line.

1

Use a zero-width box at the beginning of the paragraph, containing the rule extending to the right margin.

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

enter image description here

You must log in to answer this question.

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