## LaTeX forum ⇒ Page Layout ⇒ Vertical 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).
Cham
Posts: 936
Joined: Sat Apr 02, 2011 4:06 pm

### Vertical ruler in the margins  Topic is solved

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 :

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

Tags:

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 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.
\documentclass[12pt]{book}\usepackage[T1]{fontenc}\usepackage[   total={6in,10in},   left=1.5in,   top=0.5in,   includeheadfoot]{geometry}\usepackage{lmodern}\usepackage{eso-pic} \newlength{\xoffset}\newlength{\thickness}\setlength{\thickness}{0.5in}\AddToShipoutPicture{%   \ifodd\value{page}%     \setlength{\offset}{0pt}%   \else     \setlength{\xoffset}{\dimexpr\paperwidth-\thickness}%   \fi   \AtPageLowerLeft{%     \put(\LenToUnit{\xoffset},0){\color{gray!50}\rule{\thickness}{\paperheight}}%   }%} \usepackage{blindtext} \begin{document}   \frontmatter   \tableofcontents    \mainmatter   \blinddocument   \blinddocument\end{document}

You did not specify the thickness of the rule.

Thorsten
LaTeX Community Moderator

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

Cham
Posts: 936
Joined: Sat Apr 02, 2011 4:06 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 ?
\newlength{\xoffset}\newlength{\thickness}\setlength{\thickness}{0.5in}\AddToShipoutPicture{%	\ifodd\value{page}%	\setlength{\offset}{0pt}%	\else	\setlength{\xoffset}{\dimexpr\paperwidth-\thickness}%   \fi   \AtPageLowerLeft{%     \put(\LenToUnit{\xoffset},0){\color{gray!20}\rule{\thickness}{\paperheight}}%   }%}

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 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.
\documentclass[12pt]{book}\usepackage[T1]{fontenc}\usepackage[   total={6in,10in},   left=1.5in,   top=0.5in,   includeheadfoot]{geometry}\usepackage{lmodern}\usepackage{eso-pic} \newlength{\xoffset}\newlength{\distance}\setlength{\distance}{0.5in}\newlength{\thickness}\setlength{\thickness}{1pt}\AddToShipoutPicture{%   \ifodd\value{page}%     \setlength{\xoffset}{\distance}%   \else     \setlength{\xoffset}{\dimexpr\paperwidth-\thickness-\distance}%   \fi   \AtPageLowerLeft{%     \put(\LenToUnit{\xoffset},0){\rule{\thickness}{\paperheight}}%   }%} \usepackage{blindtext} \begin{document}   \frontmatter   \tableofcontents    \mainmatter   \blinddocument\blinddocument\end{document}

To see the output click on "Open in writeLaTeX" in the head of the above code box.
LaTeX Community Moderator

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

Cham
Posts: 936
Joined: Sat Apr 02, 2011 4:06 pm
Ah ! Now it's working great !

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

Cham
Posts: 936
Joined: Sat Apr 02, 2011 4:06 pm
Ok, how do you control the vertical position of the line ?

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

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 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.
\documentclass[12pt]{book}\usepackage[T1]{fontenc}\usepackage[   total={6in,10in},   left=1.5in,   top=0.5in,   includeheadfoot]{geometry}\usepackage{lmodern}\usepackage{eso-pic} \newlength{\distance}\setlength{\distance}{0.5in}\newlength{\rulethickness}\setlength{\rulethickness}{1pt}\newlength{\ruleheight}\setlength{\ruleheight}{9in}\newlength{\xoffset}\newlength{\yoffset}\setlength{\yoffset}{0.5\dimexpr\paperheight-\ruleheight} \AddToShipoutPicture{%   \ifodd\value{page}%     \setlength{\xoffset}{\distance}%   \else     \setlength{\xoffset}{\dimexpr\paperwidth-\rulethickness-\distance}%   \fi   \AtPageLowerLeft{%     \put(\LenToUnit{\xoffset},\LenToUnit{\yoffset}){\rule{\rulethickness}{\ruleheight}}%   }%} \usepackage{blindtext} \begin{document}   \frontmatter   \tableofcontents    \mainmatter   \blinddocument   \blinddocument\end{document}

The \AddToShipoutPicture macro is described in the eso-pic manual.
LaTeX Community Moderator

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

Cham
Posts: 936
Joined: Sat Apr 02, 2011 4:06 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 !

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.

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 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

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