0

I'm using the titlesec package to style my section titles, including centring and colouring them. Sometimes my sections appear in a minipage because I often have long narrow diagrams that run the length of the page, and I want the text alongside it. However, I'm finding that when the \section occurs at the start of a minipage, there's extra vertical space at the top of the page. The following MWE shows this:

\documentclass[10pt]{article}
\usepackage[a6paper,showframe]{geometry}

\usepackage{xcolor}
\definecolor{headcol}{cmyk}{0,.75,.75,.2}
\usepackage{titlesec}
\newcommand\sectheadfont{\fontsize{12pt}{14.4pt}\selectfont\color{headcol}}
\titleformat{\section}[block]{\sectheadfont}{}{0pt}{\filcenter}

\begin{document}
\section{Foo}
\clearpage

\begin{minipage}[t]{0.8\textwidth}
\section{Bar}
\end{minipage}
\end{document}

The first page has no space before the title, while the second page has 1em of space above it. If I comment out the \titleformat line, this doesn't happen. Moreover, if I remove \color{headcol} from the definition of \sectheadfont it doesn't. Something about the way I'm requested a coloured heading is responsible for the extra space.

I know I can manually sort it out with a \vspace{-1em} at the start of the minipage, but this seems a bit fragile as the exact space needed seems to be dependent on the font size and other such things, and not always exactly 1em. Can anyone help me fix this in my preamble?

2
  • 1
    What about \begin{minipage}[b]{0.8\textwidth}?
    – Ivan
    Apr 25, 2021 at 14:43
  • @Ivan That does fix it in the MWE, but it will cause problems in my real code as I typically have two minipage environments of unequal heights next to each other, and rely on the [t] to align them relative to each other. This is perhaps a clue as to why the MWE is incorrectly aligned, though I'm not sure I can interpret that clue.
    – richard
    Apr 25, 2021 at 15:13

2 Answers 2

1

I honestly cannot understand the reason for a structure of this type. Anyway, to remove the space before the minipage should be enough:

\vspace{-\abovedisplayskip}

In the MWE below I have defined the new strangeenv environment, but you can also do without it and simply use:

\begin{minipage}[t]{0.8\textwidth}
  \vspace{-\abovedisplayskip}
\section{Bar}
...

\end{minipage}

MWE

\documentclass[10pt]{article}
\usepackage[a6paper,showframe]{geometry}
\usepackage{kantlipsum}
\usepackage{xcolor}
\definecolor{headcol}{cmyk}{0,.75,.75,.2}
\usepackage{titlesec}
\newcommand\sectheadfont{\fontsize{12pt}{14.4pt}\selectfont\color{headcol}}
\titleformat{\section}[block]{\sectheadfont}{}{0pt}{\filcenter}

\newenvironment{strangeenv}[1]
  {\begin{minipage}[t]{#1}
    \vspace{-\abovedisplayskip}}
  {\end{minipage}}

\begin{document}
\section{Foo}
\kant[1]
\clearpage
    
\begin{strangeenv}{0.8\textwidth}
\section{Bar}
\kant[9]

\end{strangeenv}
\end{document}

enter image description here

1

If you want to run text and tall narrow images side by side, I recommend paracol.

\documentclass[10pt]{article}
\usepackage[a6paper,showframe]{geometry}

\usepackage{xcolor}
\definecolor{headcol}{cmyk}{0,.75,.75,.2}
\usepackage{titlesec}
\newcommand\sectheadfont{\fontsize{12pt}{14.4pt}\selectfont\color{headcol}}
\titleformat{\section}[block]{\sectheadfont}{}{0pt}{\filcenter}

\usepackage{paracol}
\globalcounter{section}

\begin{document}
\section{Foo}
\clearpage

\setcolumnwidth{0.8\textwidth}
\begin{paracol}{2}
\section{Bar}
\switchcolumn
\noindent\rule{\columnwidth}{\textheight}
\end{paracol}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .