Generalparagraph with vertical rule on the side?

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
sfranky
Posts: 9
Joined: Thu Nov 29, 2007 3:21 pm

paragraph with vertical rule on the side?

Post by sfranky »

hi everyone!
is there a way I can have a vertical rule on the left side of a paragraph? I tried with minipage but the problem is I can't figure out a way to determine the height of the rule, since the rule should depend on the height of the paragraph...Of course there's no point in doing it manually everytime..
What i have is mind is what the "changebar" package does, only I do not want it for revisioning..
thanks in advance!
sotiris

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

paragraph with vertical rule on the side?

Post by Juanjo »

I didn't knew the package changebar. After a quick look, I think it does exactly what you want. You can use it even if you do not plan to do revisioning.

If you finally decide to try other approach, perhaps you may find useful the following code:

Code: Select all

\newsavebox{\mybox}
\newlength{\mydepth}
\newlength{\myheight}

\newenvironment{sidebar}%
{\begin{lrbox}{\mybox}\begin{minipage}{\textwidth}}%
{\end{minipage}\end{lrbox}%
 \settodepth{\mydepth}{\usebox{\mybox}}%
 \settoheight{\myheight}{\usebox{\mybox}}%
 \addtolength{\myheight}{\mydepth}%
 \noindent\makebox[0pt]{\hspace{-20pt}\rule[-\mydepth]{1pt}{\myheight}}%
 \usebox{\mybox}}
This code defines an environment for writing text with a vertical rule of the left. You can change the width of the rule (1pt) and the separation from the left margin (20pt).

Put the above code in the preamble and try something like

Code: Select all

\begin{sidebar}
 Text text text text \par
 More lines of text ....\par
 Text text text.
\end{sidebar}
Please, take into account that this environment puts text into a minipage. This may cause problems if a page break should happen in the middle of the text, since the minipage will not be splitted.
sfranky
Posts: 9
Joined: Thu Nov 29, 2007 3:21 pm

Re: paragraph with vertical rule on the side?

Post by sfranky »

thanks very much for your help!! this is exactly what I needed!
I have searched and searched over the web to find how to do this, but I couldn't.. how do you even learn to construct such things?? is there a special tutorial for this? i have looked in books and tutorials but i don't think they cover that sort of thing..
thanks again,
sotiris

ps. is it too troublesome to change the colour of the rule? eg to gray? :oops:
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

paragraph with vertical rule on the side?

Post by Juanjo »

how do you even learn to construct such things?? is there a special tutorial for this? i have looked in books and tutorials but i don't think they cover that sort of thing..


This kind of things are in good books like The LaTeX Companion, by Goosens et al., A Guide to LaTeX2e, by Kopka and Daly, and, of course, LaTeX: A Document Preparation System, by Lamport. I recommend you to buy, if you can, one of these books.
is it too troublesome to change the colour of the rule? eg to gray?


Add \usepackage{color} to the preamble and insert, for example, \color[gray]{0.3} just before \rule in the definition of sidebar. Read the documentation of the color package to learn how to specify colors. You can use instead the xcolor package for a more sophisticated manipulation of colors.
sfranky
Posts: 9
Joined: Thu Nov 29, 2007 3:21 pm

Re: paragraph with vertical rule on the side?

Post by sfranky »

thanks for your help!! I've seen the book you mention in my uni, and I used to look up things in there, but at that time my knowledge was even smaller and I looked for simpler things)
thaaanks!
Post Reply