3

I want to have a single \subsection printed significantly larger, without otherwise changing the font. This is for a landscape page, to put a subsection title before a full-page diagram, and it needs to be included in the table of contents.

I tried using

\huge{\subsection{Big subsection heading}}

but it doesn't modify the text at all.

Ideally, the solution would use the existing font (rather than hardcoding a font choice which matches the font in this example).

So I tried creating the table-of-contents entry with \nosubsection (custom), and then using \thesubsection with the title to create a 'fake' subsection heading.

MWE:

\documentclass[12pt, a4paper]{article}

\usepackage{lipsum}

% don't recall source
\newcommand{\nosubsection}[1]{%
  \refstepcounter{subsection}%
  \addcontentsline{toc}{subsection}{\protect\numberline{\thesubsection}#1}%
  \markright{#1}}

% http://tex.stackexchange.com/questions/73158/how-to-get-the-size-of-the-section-header
\newcommand{\getsubsectionfont}{\setbox0=\vbox{\subsection*{a\xdef\TheSubsectionFont{\the\font}}}}
\AtBeginDocument{\getsubsectionfont}


\begin{document}

\section{Section heading}
\subsection{Normal subsection heading}

% Note the separate \centering
\nosubsection{Big subsection heading}
\centering{\TheSubsectionFont\huge{\thesubsection{} Big subsection heading}}
\label{sec:big}

% Don't know why this is centred too, but it doesn't matter
\lipsum[66]

\end{document}

MWE output:

MWE output

  • It accomplishes the same thing, thank you. I'm inclined to use @GonzaloMedina's solution because it seems less 'hacky', but yours is usable too. If you submit it as an answer I'll vote it up. – David Lord Feb 2 '15 at 1:14
5

One option using titlesec to define two commands to switch at will between the desired formatting:; use \largesubsection as many times as desired and at any point, to switch to the larger format; \stdsection switches back to the regular format.

enter image description here

The code:

\documentclass[12pt, a4paper]{article}
\usepackage{titlesec}
\usepackage{lipsum}

\newcommand\stdsubsection{%
  \titleformat{\subsection}
    {\normalfont\large\bfseries}{\thesubsection}{1em}{}
}
\newcommand\largesubsection{%
  \titleformat{\subsection}
    {\normalfont\huge\bfseries\filcenter}{\thesubsection}{1em}{}
}

\begin{document}

\section{Section heading}
\subsection{Normal subsection heading}

\largesubsection
\subsection{Big subsection heading}
\lipsum[66]

\stdsubsection
\subsection{Another normal subsection heading}

\end{document}

With \titleformat*, the code simplifies a little:

\documentclass[12pt, a4paper]{article}
\usepackage{titlesec}
\usepackage{lipsum}

\newcommand\stdsubsection{%
  \titleformat*{\subsection}
    {\normalfont\large\bfseries}
}
\newcommand\largesubsection{%
  \titleformat*{\subsection}{\normalfont\huge\bfseries\filcenter}
}

\begin{document}

\section{Section heading}
\subsection{Normal subsection heading}

\largesubsection
\subsection{Big subsection heading}
\lipsum[66]

\stdsubsection
\subsection{Another normal subsection heading}

\end{document}
  • I'm surprised by how different the "big" font is from the others, but adding bfseries to \largesubsection makes it look more like the others. Is this an unavoidable consequence of the bolded/unbolded fonts? – David Lord Feb 2 '15 at 1:13
  • @DavidLord I suppressed the boldface from the larger headings because it seemed too much (\huge size bold-faced titles stand too much for my liking), but you can, of course, add \bfseries. I am afraid I don't understand what do you mean by the unavoidable consequence. Could you please elaborate? – Gonzalo Medina Feb 2 '15 at 1:16
  • Poorly-phrased on my part: the character of the font seems quite different with bold and unbold. Fortunately, in my use case the bold is useful (the secton heading needs to stand out on the page against a diagram), so this is perfect with the addition of \bfseries. Thank you. – David Lord Feb 2 '15 at 1:20
  • @DavidLord You're welcome! Ah, now I see what you meant. I added \bfseries in my updated answer and provided a shorter version of the code. – Gonzalo Medina Feb 2 '15 at 1:27

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.