11

I’m trying to help a friend set an Arabic book in LaTeX and I’m facing this very same uneven line spacing issue (except that the book is completely in Arabic).

Now I’m trying to find the \linespread setting that is just big enough to ensure even line spacing but not any bigger, so I thought drawing a grid and visually examining the lines with different setting to find the desired ones.

But, I do not even understand what, say, 1.5 in \linespread{1.5} actually mean (I read many discussions and answers but I still don’t get it), so I need help in:

  • Setting a background grid (horizontal lines are enough).
  • Make the spacing between grid lines follow \linespread setting i.e. they should represent the ideal line spacing if TeX didn’t do its vertical glue magic.

(I tried grid option of eso-pic but couldn’t wrap my head around the meaning of its options to get what I described above).

10

This should do what you want. A box consisting of the requested number of lines, drawn at the baselines, is added with \AtBeginShipout.

\documentclass{article}
\usepackage{atbegshi,picture,xcolor}
\AtBeginShipout{%
  \AtBeginShipoutUpperLeft{%
    \color{red}%
    \put(\dimexpr 1in+\oddsidemargin,
         -\dimexpr 1in+\topmargin+\headheight+\headsep+\topskip)%
      {%
       \vtop to\dimexpr\vsize+\baselineskip{
         \hrule
         \leaders\vbox to\baselineskip{\hrule width\hsize\vfill}\vfill
       }%
      }%
  }%
}

\linespread{1.5}

\usepackage{kantlipsum}

\begin{document}
\kant
\end{document}

enter image description here

What does \linespread{1.5} do? Every time LaTeX does a setting of \baselineskip, it will multiply the normal value by that factor. For instance, if the normal baselineskip is 12pt, it will become 18pt; for \small, when the normal value is 11pt, it will become 16.5pt. However, \topskip is not modified.

3
  • Thanks, it does not seems not to play nice with bidi when the document is set to RTL (i.e. \usepackage[rldocument]{bidi}) generating some warnings and the grid is displaced, but I can live with that. Dec 19 '13 at 6:43
  • @egreg It's a helpful post, would you please help hint me how to put 3 line grid for each text line? one on top, one on middle and another one on bottom.
    – lucky1928
    Mar 14 '18 at 18:01
  • @lucky1928 That's quite an addition. Please, ask a follow-up question.
    – egreg
    Mar 14 '18 at 21:34
3

With package bidi-atbegshi, this even becomes much easier (you only have to change \AtBeginShipoutUpperLeft in @egreg's code to \AtBeginShipoutUpperRight:

\documentclass{article}
\usepackage{bidi-atbegshi,picture,xcolor}
\usepackage[RTLdocument]{bidi}
\AtBeginShipout{%
  \AtBeginShipoutUpperRight{%
    {\color{red}%
    \put(\dimexpr 1in+\oddsidemargin,
         -\dimexpr 1in+\topmargin+\headheight+\headsep+\topskip)%
      {%
       \vtop to\dimexpr\vsize+\baselineskip{
         \hrule
         \leaders\vbox to\baselineskip{\hrule width\hsize\vfill}\vfill
       }%
      }%
  }%
 }%
}

\linespread{1.5}

\usepackage{kantlipsum}

\begin{document}
\kant
\end{document}
0

With a little change to @egreg's code, this works fine in RTL too:

\documentclass{article}
\usepackage{atbegshi,picture,xcolor}
\usepackage[RTLdocument]{bidi}
\AtBeginShipout{%
  \AtBeginShipoutUpperLeft{%
    {\color{red}%
    \put(\dimexpr -1in-\oddsidemargin,
         -\dimexpr 1in+\topmargin+\headheight+\headsep+\topskip)%
      {%
       \vtop to\dimexpr\vsize+\baselineskip{
         \hrule
         \leaders\vbox to\baselineskip{\hrule width\hsize\vfill}\vfill
       }%
      }%
  }}%
}

\linespread{1.5}

\usepackage{kantlipsum}

\begin{document}
\kant
\end{document}

and here is what you get:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.