LaTeX forum ⇒ Page LayoutVertical ruler in the margins Topic is solved

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
User avatar
Cham
Posts: 934
Joined: Sat Apr 02, 2011 4:06 pm

Vertical ruler in the margins  Topic is solved

Postby Cham » Sat Jun 29, 2013 6:00 pm

How can I add a vertical line inside the margins, on all the pages of a double-sided document (book class) ?

More specifically, the line should take all the height of the page, and be placed on the left of the first page (odd number), on the right of the second page (even number), and so on. Take note that the line should also appears on the pages with a roman number (i, ii, iii, iv, ... for the ToC and other frontmatter contents).

The line's horizontal distance from the paper's border should be 0.5in.

Here's a mwe, without the vertical line :

  1. \documentclass[12pt,letterpaper,twoside]{book}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{lmodern}
  4. \usepackage[total={6in,10in},left=1.5in,top=0.5in,includehead,includefoot]{geometry}
  5. \usepackage{lipsum}
  6.  
  7. \begin{document}
  8.  
  9. \frontmatter
  10. \tableofcontents
  11.  
  12. \mainmatter
  13. \chapter{Test chapter one}
  14. \lipsum[1-7]\clearpage
  15.  
  16. \chapter{Test chapter two}
  17. \lipsum[1-10]
  18.  
  19. \end{document}
Last edited by Cham on Sat Jun 29, 2013 6:49 pm, edited 2 times in total.

Tags:

User avatar
localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Sat Jun 29, 2013 6:49 pm

Cham wrote:[…] More specifically, the line should take all the height of the page, and be placed on the left of the first page (odd number), on the right of the second page (even number), and so on. […]

In short: on all inner margins.

Take a look at this first approach. Further customization possible.
  1. \documentclass[12pt]{book}
  2. \usepackage[T1]{fontenc}
  3. \usepackage[
  4. total={6in,10in},
  5. left=1.5in,
  6. top=0.5in,
  7. includeheadfoot
  8. ]{geometry}
  9. \usepackage{lmodern}
  10. \usepackage{eso-pic}
  11.  
  12. \newlength{\xoffset}
  13. \newlength{\thickness}
  14. \setlength{\thickness}{0.5in}
  15. \AddToShipoutPicture{%
  16. \ifodd\value{page}%
  17. \setlength{\offset}{0pt}%
  18. \else
  19. \setlength{\xoffset}{\dimexpr\paperwidth-\thickness}%
  20. \fi
  21. \AtPageLowerLeft{%
  22. \put(\LenToUnit{\xoffset},0){\color{gray!50}\rule{\thickness}{\paperheight}}%
  23. }%
  24. }
  25.  
  26. \usepackage{blindtext}
  27.  
  28. \begin{document}
  29. \frontmatter
  30. \tableofcontents
  31.  
  32. \mainmatter
  33. \blinddocument
  34. \blinddocument
  35. \end{document}

You did not specify the thickness of the rule.


Thorsten
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

User avatar
Cham
Posts: 934
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Sat Jun 29, 2013 7:42 pm

I'm getting error messages from your code (which isn't working in WriteLaTeX either). \mainmatter not recognised ?

The line should be 1pt in thickness.

EDIT : Apparently, there's a problem in that part (which I don't understand yet). I guess it's a line thickness parameter missing ?
  1. \newlength{\xoffset}
  2. \newlength{\thickness}
  3. \setlength{\thickness}{0.5in}
  4. \AddToShipoutPicture{%
  5. \ifodd\value{page}%
  6. \setlength{\offset}{0pt}%
  7. \else
  8. \setlength{\xoffset}{\dimexpr\paperwidth-\thickness}%
  9. \fi
  10. \AtPageLowerLeft{%
  11. \put(\LenToUnit{\xoffset},0){\color{gray!20}\rule{\thickness}{\paperheight}}%
  12. }%
  13. }
  14.  

User avatar
localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Sat Jun 29, 2013 7:54 pm

Cham wrote:I'm getting error messages from your code. \mainmatter not recognised ?[…]

But \mainmatter is also in your code. I tested my code and it works.

Cham wrote:[…] The line should be 1pt in thickness.

See this example with the corresponding modifications.
  1. \documentclass[12pt]{book}
  2. \usepackage[T1]{fontenc}
  3. \usepackage[
  4. total={6in,10in},
  5. left=1.5in,
  6. top=0.5in,
  7. includeheadfoot
  8. ]{geometry}
  9. \usepackage{lmodern}
  10. \usepackage{eso-pic}
  11.  
  12. \newlength{\xoffset}
  13. \newlength{\distance}
  14. \setlength{\distance}{0.5in}
  15. \newlength{\thickness}
  16. \setlength{\thickness}{1pt}
  17. \AddToShipoutPicture{%
  18. \ifodd\value{page}%
  19. \setlength{\xoffset}{\distance}%
  20. \else
  21. \setlength{\xoffset}{\dimexpr\paperwidth-\thickness-\distance}%
  22. \fi
  23. \AtPageLowerLeft{%
  24. \put(\LenToUnit{\xoffset},0){\rule{\thickness}{\paperheight}}%
  25. }%
  26. }
  27.  
  28. \usepackage{blindtext}
  29.  
  30. \begin{document}
  31. \frontmatter
  32. \tableofcontents
  33.  
  34. \mainmatter
  35. \blinddocument
  36. \blinddocument
  37. \end{document}

To see the output click on "Open in writeLaTeX" in the head of the above code box.
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

User avatar
Cham
Posts: 934
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Sat Jun 29, 2013 8:01 pm

Ah ! Now it's working great ! :-)

I'll play a little with this, trying to understand how the code is working.

User avatar
Cham
Posts: 934
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Sat Jun 29, 2013 8:09 pm

Ok, how do you control the vertical position of the line ?

What if we want a 9in line, vertically centered on the page ?

User avatar
localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Sat Jun 29, 2013 8:40 pm

Cham wrote:Ok, how do you control the vertical position of the line ?

What if we want a 9in line, vertically centered on the page ?

Simple mathematics.

Would be nice if tell us your wishes all at once and not only step by step.
  1. \documentclass[12pt]{book}
  2. \usepackage[T1]{fontenc}
  3. \usepackage[
  4. total={6in,10in},
  5. left=1.5in,
  6. top=0.5in,
  7. includeheadfoot
  8. ]{geometry}
  9. \usepackage{lmodern}
  10. \usepackage{eso-pic}
  11.  
  12. \newlength{\distance}
  13. \setlength{\distance}{0.5in}
  14. \newlength{\rulethickness}
  15. \setlength{\rulethickness}{1pt}
  16. \newlength{\ruleheight}
  17. \setlength{\ruleheight}{9in}
  18. \newlength{\xoffset}
  19. \newlength{\yoffset}
  20. \setlength{\yoffset}{0.5\dimexpr\paperheight-\ruleheight}
  21.  
  22. \AddToShipoutPicture{%
  23. \ifodd\value{page}%
  24. \setlength{\xoffset}{\distance}%
  25. \else
  26. \setlength{\xoffset}{\dimexpr\paperwidth-\rulethickness-\distance}%
  27. \fi
  28. \AtPageLowerLeft{%
  29. \put(\LenToUnit{\xoffset},\LenToUnit{\yoffset}){\rule{\rulethickness}{\ruleheight}}%
  30. }%
  31. }
  32.  
  33. \usepackage{blindtext}
  34.  
  35. \begin{document}
  36. \frontmatter
  37. \tableofcontents
  38.  
  39. \mainmatter
  40. \blinddocument
  41. \blinddocument
  42. \end{document}

The \AddToShipoutPicture macro is described in the eso-pic manual.
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

User avatar
Cham
Posts: 934
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Sat Jun 29, 2013 8:54 pm

localghost wrote:
Cham wrote:Would be nice if tell us your wishes all at once and not only step by step.


Well, to be honest, I'm not even sure to know what I want/need with this line ! :oops:

Currently, I'm discovering and experimenting with the vertical line. Since the result looks very good, I'll most probably keep it.

But anyway, thanks a lot for your help. It's very appreciated, and I'm sure other users would find this topic usefull.

User avatar
localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Sat Jun 29, 2013 8:58 pm

Cham wrote:Well, to be honest, I'm not even sure to know what I want/need with this line ! :oops:

Currently, I'm discovering and experimenting with the vertical line. Since the result looks very good, I'll most probably keep it. […]

OK. That's comprehensible. Feel free to ask follow-up questions if you have a more concrete idea of the final result.
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1


Return to “Page Layout”

Who is online

Users browsing this forum: No registered users and 2 guests