# Preventing letters with descenders (g, q, y…) from affecting line spacing

I'm making layouts for a card game, and characters that have a descender component (like g, q, y...) are messing up the spacing. For example:

\documentclass{article}
\usepackage{graphicx}
\usepackage{mwe}
\begin{document}
blah
\\[0.2\baselineskip]
\includegraphics[width=4cm]{example-image}
\end{document}


results in the image being placed higher than

\documentclass{article}
\usepackage{graphicx}
\usepackage{mwe}
\begin{document}
glah
\\[0.2\baselineskip]
\includegraphics[width=4cm]{example-image}
\end{document}


How can I prevent this (without having to place things in different nodes or anything like that)? Right now I'm adding \vphantom{g} (or \strut) to lines that don't have descenders, but it's not a very elegant solution.

Right now the only time I see this arise is with \baselineskip (and it is indeed possible to avoid using those), but I'm doing a bunch of things that need to be independent of the letters used. I'm already using a ttfamily font so they take up the same horizontal space, it'd be really nice if they could also take up the same vertical space.

• Please make your code snippets compilable ... – Kurt Mar 18 '18 at 7:13
• Is the image important? Does there have to be an image? Maybe \rule{2cm}{2cm} does just fine? – Johannes_B Mar 18 '18 at 7:21
• Use \strut at the beginning of those lines (blahblah and glahglah). – Johannes_B Mar 18 '18 at 7:22
• @Johannes_B yeah, using \strut works, but it's not much better than using \vphantom{g}, I still have to put it manually on every offending line. Isn't there a way to do it globally? – Alexbib Mar 18 '18 at 7:27
• @Alexbib Yes sure, use or create a [virtual] font in which all letters take the same vertical space (e.g. change the font metrics). Or use \strut on every line. Or change the values of \baselineskip, \lineskip and \lineskiplimit, to change the behaviour of the interline glue. Or include every letter in a box. Or other solutions; it's really hard to say what's best without knowing the use-case. – ShreevatsaR Mar 18 '18 at 8:49

Remove the previous depth before adding the vertical space.

\documentclass{article}
\usepackage{graphicx}

\newcommand{\fixedvspace}[1]{%
\par\kern-\prevdepth\vspace{#1}%
}

\begin{document}

\begin{minipage}[t]{4cm}
\hrule

blah
\fixedvspace{0.2\baselineskip}
\includegraphics[width=4cm]{example-image}

\end{minipage}%
\begin{minipage}[t]{4cm}
\hrule

glah
\fixedvspace{0.2\baselineskip}
\includegraphics[width=4cm]{example-image}

\end{minipage}

\end{document}


The \hrule here is just to anchor the minipage to have the reference point at the very top.

There may be simpler workarounds in your specific setting that seems quite specialized. The trick could be hidden in the syntax you use for laying out the card game.

• Awesome, this way seems pretty logical! – Alexbib Mar 18 '18 at 18:52

The problem isn't so much the descender in the text as the fact that the height of the image forces \lineskip glue spacing. LaTeX doesn't have that good a way to avoid that but you can do this

\documentclass{article}
\usepackage{graphicx}

\showoutput
\begin{document}

glah

\mbox{}\\
\includegraphics[width=4cm]{example-image}

\end{document}


so that you get \baselineskip spacing between the text and the empty \mbox (which therefore adjusts to the depth of the text) and get a fixed \lineskip spacing in all cases before the image. If the empty box line is more space than you want use \\[-\baselineskip] or whatever instead of \\ after the \mbox{}

Even if David Carlisle's vision is better, you may use something like this (with your actual code), with the calc package ans its depthof calculation :

\documentclass{article}
\usepackage{graphicx}
\usepackage{mwe}
\usepackage{calc}

\begin{document}
\newlength{\abc}
\newlength{\nabc}
\setlength{\abc}{\depthof{glah}}
\setlength{\nabc}{-\abc}

\rule[\nabc]{0pt}{0pt}blah
\\[0.2\baselineskip]
\includegraphics[width=4cm]{example-image}

glah
\\[0.2\baselineskip]
\includegraphics[width=4cm]{example-image}
\end{document}
`