LaTeX forum ⇒ Generalparagraph with vertical rule on the side?

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

paragraph with vertical rule on the side?

Postby sfranky » Mon Dec 10, 2007 6:40 pm

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

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
Juanjo
Posts: 656
Joined: Sat Jan 27, 2007 12:46 am

Postby Juanjo » Mon Dec 10, 2007 9:14 pm

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:

  1. \newsavebox{\mybox}
  2. \newlength{\mydepth}
  3. \newlength{\myheight}
  4.  
  5. \newenvironment{sidebar}%
  6. {\begin{lrbox}{\mybox}\begin{minipage}{\textwidth}}%
  7. {\end{minipage}\end{lrbox}%
  8. \settodepth{\mydepth}{\usebox{\mybox}}%
  9. \settoheight{\myheight}{\usebox{\mybox}}%
  10. \addtolength{\myheight}{\mydepth}%
  11. \noindent\makebox[0pt]{\hspace{-20pt}\rule[-\mydepth]{1pt}{\myheight}}%
  12. \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

  1. \begin{sidebar}
  2. Text text text text \par
  3. More lines of text ....\par
  4. Text text text.
  5. \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.

Link:
BBcode:
HTML:
Hide post links
Show post links

sfranky
Posts: 9
Joined: Thu Nov 29, 2007 3:21 pm

Postby sfranky » Tue Dec 11, 2007 10:44 am

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? Embarassed

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
Juanjo
Posts: 656
Joined: Sat Jan 27, 2007 12:46 am

Postby Juanjo » Tue Dec 11, 2007 12:11 pm

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.

Link:
BBcode:
HTML:
Hide post links
Show post links

sfranky
Posts: 9
Joined: Thu Nov 29, 2007 3:21 pm

Postby sfranky » Tue Dec 11, 2007 1:08 pm

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!

Link:
BBcode:
HTML:
Hide post links
Show post links


Return to “General”

Who is online

Users browsing this forum: Google [Bot] and 8 guests