I use the following layout where the \sec{}
headers are placed in the margin and \subsec{}
headers and text paragraphs are position in the main column next to it.
However, when a \subsec{}
immediately follows \sec{}
, I would like both to start on the same line without vertical space. The issue is that I can't just include negative space in one of the commands because \subsec{}
should still create spacing when it follows anything other than \sec{}
. How can I achieve this?
Here is a small example that shows the unwanted space, where I would want SECTION and Subsection to start on the same line and keep all other spacing as it is:
\documentclass{article}
\usepackage{calc}
\usepackage{changepage}
\usepackage{lipsum}
\setlength{\parskip}{.5em}
\setlength{\parindent}{0em}
\newcommand{\titlecol}{1.45in}
\newcommand{\titlesep}{0.5em}
\newcommand{\secskip}{1.6em}
\newcommand{\subsecskip}{0.6em}
\renewcommand{\sec}[1]{%
\vspace{\secskip}\hspace{-\titlecol}%
\parbox[t][0pt][t]{\titlecol-\titlesep}{#1\raggedright}}
\newcommand{\subsec}[1]{\vspace{\subsecskip}\textbf{#1}\par}
\begin{document}
\begin{adjustwidth}{\titlecol}{0em}
\sec{SECTION}
\subsec{Subsection}
\lipsum[1][1-2] \par
\lipsum[1][3]
\subsec{Subsection}
\lipsum[1][1-3]
\sec{ANOTHER SECTION}
\lipsum[1][1-3]
\end{adjustwidth}
\end{document}
\titlesec
butleftmargin
didn't work anddrop
had a similar issue to the one described in my question here. I opened a question about it but gave up this route because it was too complex and hard to find help. You can see the solution below, which uses\nopagebreak
to prevent the issue you described.