Text FormattingProblem with titlesec...

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
tinley.geo
Posts: 2
Joined: Wed Jan 13, 2010 12:10 am

Problem with titlesec...

Post by tinley.geo »

I'm writing/formatting my thesis in LaTeX and have been very successful so far. I only have one small but major issue and it is with titlesec. I use it to equally space my section/subsection from the paragraphs. The only issue is after the first heading if I do a \newpage or \pagebreak command, it puts the next heading at a slightly lower spacing until the next page without a section heading. Here is an example

Code: Select all

\documentclass[12pt]{article}
\usepackage{geometry}
\geometry{letterpaper,tmargin=1in,bmargin=1in,lmargin= 1.25in,rmargin=1in}
\usepackage{setspace}
\usepackage[noindentafter]{titlesec}

%______________Title Settings___________________
\titleformat{\section}{
\centering\large\bfseries}{\thesection}{1em}{}
\titlespacing{\section}{0pt}{*0}{*0}

\begin{document}
\section*{Introduction}
\begin{doublespace}
\thispagestyle{empty}

\centering Text Text Text Text Text Text Text Text Text Text Text Text\\
Text Text Text Text Text Text Text Text Text Text Text Text Text Text\\
Text Text Text Text Text Text Text Text Text Text Text Text \\
Text Text Text Text Text Text\\

\newpage
\section*{Marine Controlled-Source Electromagnetics}
\thispagestyle{empty}

This Heading is approximately 1 halfspace below the previous!?\\
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text \\
Text Text Text Text Text Text Text Text Text Text Text Text Text Text\\
Text Text Text Text Text Text Text Text Text Text Text Text\\
Text Text Text Text Text Text\\

\end{doublespace}
\end{document}
As soon as I remove the titlesec settings it goes back to normal. I have messed around with the setspace settings and am pretty much out of ideas. Any help would be fantastic.

Thanks everyone

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

Problem with titlesec...

Post by meho_r »

Move \begin{doublespace} before \section*{Introduction}.

However, it is not recommended to use doublespace this way. If you need it for a whole doc, put in the Preamble \doublespacing. And about \centering: you shouldn't let it flow through the text without limiting it (enclosing it inside curly brackets or some environment); instead, use \begin{center}...\end{center} and avoid including sectioning commands inside these (or any other) environments.

Your example, a little bit changed:

Code: Select all

\documentclass[12pt]{article}
\usepackage{geometry}
\geometry{letterpaper,tmargin=1in,bmargin=1in,lmargin= 1.25in,rmargin=1in}
\usepackage{setspace}
\doublespacing
\usepackage[noindentafter]{titlesec}

%______________Title Settings___________________
\titleformat{\section}{
\centering\large\bfseries}{\thesection}{1em}{}
\titlespacing{\section}{0pt}{*0}{*0}

\begin{document}
\section*{Introduction}
%\begin{doublespace}
\thispagestyle{empty}

%\centering
\begin{center}
Text Text Text Text Text Text Text Text Text Text Text Text\\
Text Text Text Text Text Text Text Text Text Text Text Text Text Text\\
Text Text Text Text Text Text Text Text Text Text Text Text \\
Text Text Text Text Text Text
\end{center}

\newpage
\section*{Marine Controlled-Source Electromagnetics}
\thispagestyle{empty}

\begin{center}
This Heading is approximately 1 halfspace below the previous!?\\
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text \\
Text Text Text Text Text Text Text Text Text Text Text Text Text Text\\
Text Text Text Text Text Text Text Text Text Text Text Text\\
Text Text Text Text Text Text
\end{center}

%\end{doublespace}
\end{document}
tinley.geo
Posts: 2
Joined: Wed Jan 13, 2010 12:10 am

Re: Problem with titlesec...

Post by tinley.geo »

meho_r,

Thanks for the reply. I think this is the major issue with my document, the double spacing. My schools format requires the ability to go back and forth between double and single spacing. So if I put it in the preamble, the entire document would be double spaced including references, etc...

Moving the \begin{doublespace} does work, but I am trying to move the second heading up, not the first heading down. Does that make any sense?

Also, I usually do use begin & end{center}. for some reason I opted not to for the example.
meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

Problem with titlesec...

Post by meho_r »

1. If for most of your text you're using single spacing, then use \begin{doublespace}...\end{doublespace} for the rest (and vice versa) as you did in the example, but try not to enclose sectioning commands inside it since the spacing affects them too (or, if you do enclose them, keep it consistent: enclose all or none). So, \begin{doublespace} should come after the current sectioning command, and \end{doublespace} should come just before the next sectioning command. However, this can be problematic too if part of text which should have double spacing includes subsections, or even some sections. It's up to you to decide what to do in these cases.

2. If you regularly use \newpage command before every section, you may use \vspace*{-1ex} inside <format> argument of \titleformat command to move the title a little bit up (where -1ex is just an example). Setting a negative value for <beforesep> argument in \titlespacing command may not work.
Post Reply