2

I'm trying to change the distance from the top of the page that text starts appearing when I use \section, so that it matches the distance when I just use regular formatting (not in a section). Below is an example of the code. From what I've read, changing the 2nd argument for titlespacing to a negative value should fix my problem, but no matter what I put as the 2nd argument (positive or negative), nothing seems to happen. Basically, I want to make the 1st page look identical to the 2nd page. Any ideas?

\documentclass[10pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{hyperref}
\usepackage{mathpazo}
\linespread{1.05}

\usepackage{titlesec}

\titleformat*{\section}{\centering\LARGE\bfseries}
\titlespacing*{\section}{0pt}{0pt}{-6pt}

\setcounter{secnumdepth}{0}

\begin{document}

\section{This is the first line of my example that should start at the same height as it does on page 2}
\centering{\large This second line is perfect where it is on both pages}

\newpage

\centering{
\LARGE \textbf{This is the first line of my example that should start at the same height as it does on page 2}\\
\large This second line is perfect where it is on both pages}

\end{document}
  • 2
    The \section title has struts at the beginning and end. – egreg Jul 7 '15 at 21:00
  • How do you modify the struts? – Josh Jul 7 '15 at 21:59
  • Anyway, the second line (actually, the third—I mean, the one that is “perfect where it is”) isn’t located at exactly the same height on both pages. It may seem so (the difference is in the order of 0.1pt), but this is a coincidence. – GuM Jul 7 '15 at 22:09
  • If you really want to get rid of the struts, you may add \setbox \strutbox \null at the end of the second argument of the \titleformat* command (after the font-switching commands). – GuM Jul 7 '15 at 22:52
0

The following is just a dirty trick that smashes down the struts inside the section title; however, it does make the two pages look exactly the same (checked with \tracingoutput):

\documentclass[a4paper]{article}
\usepackage[margin=1in]{geometry}
\usepackage{mathpazo}
\usepackage{titlesec}
\usepackage{hyperref}

\linespread{1.05}

\titleformat*{\section}{%
    \centering\LARGE\bfseries
    \setbox \strutbox \null
%   \showbox\strutbox
}
\titlespacing*{\section}{0pt}{0pt}{0pt}

\setcounter{secnumdepth}{0}

% \showboxbreadth = 1000
% \showboxdepth = 10
% \tracingoutput = 1

\begin{document}

\section{This is the first line of my example that should start at the same height as it does on page 2}
{\centering\large This second line is perfect where it is on both pages\par}

% \showlists

\newpage

{\centering
\LARGE \textbf{This is the first line of my example that should start at the 
same height as it does on page 2}\par
\large This second line is perfect where it is on both pages\par}

% \showlists

\end{document}

(Note: I’ve tidied up the OP’s code in a couple of points I didn’t noticed yesterday night.) You may enjoy uncommenting the diagnostic commands to check exactly what is going on.

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.