5

In answering the question Underline subsections, I provided an answer which relied on the sectsty package (as compared to @GonzaloMedina's answer, which used the titlesec package).

Ultimately, @GonzaloMedina's answer was more helpful, as the OP was also using lineno to number lines and it seems that there is no incompatibility between this package and titlesec and ulem, whereas there is an apparent joint incompatibility between sectsty, lineno, and ulem.

Specifically, it seems that, at least when you use any of the commands made available by sectsty to modify the appearance of sections (e.g., \allsectionsfont{}, \sectionfont{}, \subsectionfont{}, etc.) in combination with ulem and \underline, an issue arises that prevents the compilation of the document. I have not been able to figure out why this is so, let alone whether there is any workaround.

I'm mostly curious why it is happening (for the sake of learning), though if you can provide a workaround as well, that would be awesome.

Here's an MWE that will crash:

\documentclass[11pt]{article}
\usepackage[normalem]{ulem}
\usepackage{sectsty}
\subsectionfont{\normalfont\large\itshape\underline} % document compiles fine without this line and/or without the \underline command in this line

\usepackage{lineno}
\linenumbers % or without this line; both lines, however, cause the compilation to crash

\begin{document}
\section*{Materials and Methods}
\subsection*{Sampling}
\subsection*{A very long sectional heading title that will probably have to be split over two lines}
Lorem ipsum
\end{document}

And the error message:

./test-sectsty.tex:11: Improper \prevdepth. \prevdepth

l.11 \subsection*{Sampling}

? ./test-sectsty.tex:11: Emergency stop. \prevdepth

l.11 \subsection*{Sampling}

The documentation for sectsty does say the following (p. 16):

The sectsty package works by blindly re-defining the various sectioning commands, so any package that requires that LaTeX's sectioning commands are precisely as they are defined in the standard classes will have trouble working with sectsty.

The fncychap package, for example, re-defines the code that produces chapter headings. If you use fncychap with sectsty, you will have to load fncychap after sectsty:

\usepackage{sectsty}
\usepackage{fncychap}

So, my suspicion is that this particular functionality of sectsty, somehow in conjunction with the way that the underlining works, is the culprit. However, changing the order in which lineno (and \linenumbers) are loaded/issued relative to loading sectsty and issuing one of the section font commands made available by sectsty and containing \underline doesn't change anything; the code still crashes.

Is my suspicion correct? If not, what's going on? If it is correct, can you provide a more detailed explanation of the incompatibility between these packages? And, if you're feeling adventurous (and if it's even possible), what is a workaround to the incompatibility?

Your Answer

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

Browse other questions tagged or ask your own question.