0

Effectively, when I make section titles, I noticed that obviously the space after them is constant, but the letters aren't mono-width, leading to weird discrepancies across them. Is there any way to make the space after a subsubsection to adapt to this so that all the starting lines are aligned?

enter image description here

MWE:

\documentclass{article}
\renewcommand{\thesubsubsection}{\alph{subsubsection})}

\begin{document}
\section{Dolor Sit Amet}
\subsubsection{Lorem Ipsum}
\subsubsection{Lorem Ipsum}
\end{document}
1

Basically, you want to right align the subsection numbers within a small space.

If this causes problems in the TOC etc., try \hbox to 1em{\hfill...} or use \protect.

\documentclass{article}
\renewcommand{\thesubsubsection}{\makebox[1em][r]{\alph{subsubsection})}}

\begin{document}
\section{Dolor Sit Amet}
\subsubsection{Lorem Ipsum}
\subsubsection{Lorem Ipsum}
\end{document}

This version modifies \@seccntformat. Rather than do a string compare, I defined different formats for every possible \@sect name.

\documentclass{article}
\usepackage{showframe}% alignment tool

\renewcommand{\thesubsubsection}{\alph{subsubsection}}

\makeatletter
\newcommand{\section@format}{\thesection\quad}
\newcommand{\subsection@format}{\thesubsection\quad}
\newcommand{\subsubsection@format}{\makebox[1em][r]{\thesubsubsection})\quad}
\newcommand{\paragraph@format}{\theparagraph\quad}
\newcommand{\subparagraph@format}{\thesubparagraph\quad}
\def\@seccntformat#1{\csname #1@format\endcsname}
\makeatother

\begin{document}
\section{Dolor Sit Amet}
\subsubsection{Lorem Ipsum}
\subsubsection{Lorem Ipsum}
\end{document}
| improve this answer | |
  • 1
    If you redefine \thesubsubsection like this you are also affecting references. It is better to change \@seccntformat. – Ulrike Fischer Feb 15 at 15:18
  • @UlrikeFischer how would you go about doing that? – It'sNotALie. Feb 15 at 15:26
  • Note that \@seccntformat is passed section, subsection, etc. as an argument. – John Kormylo Feb 15 at 15:31
  • you don't have to define a format for every level. You could do something like \ifcsname #1@format\endcsname \csname#1@format\endcsname \else \csname the#1\endcsname\quad\fi, and then define only the new \subsubsection@format. – Ulrike Fischer Feb 15 at 18:49
  • @UlrikeFischer - or use \@ifundefined etc. OTOH, I have always preferred jump vectors to test-and-branch. – John Kormylo Feb 16 at 1:49

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.