0

I cannot for the life of me get my section title to center properly. I want the general layout of the document to have a fairly large left margin (3.0in). When I want something to move into that margin, say a picture, I use adjustwidth. This works fine for things like figures. I am trying to do a similar approach with section titles and it is not working. It keeps centering it above the text that has the 3.0in margin instead of centering it on the page like I want. Or it will place it about 1/3 the way across the page.. What am I doing wrong?

MWE:

\documentclass{article}

\usepackage[left=3.0in, right=1.0in, top=1.0in, bottom=1.0in, marginparwidth=2.0in]{geometry}
\usepackage[export]{adjustbox}
\usepackage{marginnote}
\usepackage{titlesec}
\usepackage{changepage}

\let\oldsection\section
\renewcommand{\section}[2][]{
  \begin{adjustwidth}{-2.0in}{0.0in}
  \begin{minipage}[t]{\textwidth}
  \oldsection{#2}
  \end{minipage}
  \end{adjustwidth}
}

%\titleformat{command}[shape]{format}{label}{sep}{before code}[after code]
\titleformat{\section}[display]{\bfseries\Large\filcenter}{Section \thesection}{0ex}{}[]

\begin{document}

\section{Introduction}

\subsection{Sub Section 1}

\subsubsection{Sub Sub Section 1}

Margin notes provide complementary information to support the main document, or can be used for additional notes while working on a collaborative project. This article explains how to use margin notes in your LATEX document.
Margin notes provide complementary information to support the main document, or can be used for additional notes while working on a collaborative project. This article explains how to use margin notes in your LATEX document.
Margin notes provide complementary information to support the main document, or can be used for additional notes while working on a collaborative project. This article explains how to use margin notes in your LATEX document.

\end{document}

Output: enter image description here

MWE Without Redefinition of Section:

\documentclass{article}

\usepackage[left=3.0in, right=1.0in, top=1.0in, bottom=1.0in, marginparwidth=2.0in]{geometry}
\usepackage[export]{adjustbox}
\usepackage{marginnote}
\usepackage{titlesec}
\usepackage{changepage}

%\titleformat{command}[shape]{format}{label}{sep}{before code}[after code]
\titleformat{\section}[display]{\bfseries\Large\filcenter}{Section \thesection}{0ex}{}[]

\begin{document}

\section{Introduction}

\subsection{Sub Section 1}

\subsubsection{Sub Sub Section 1}

Margin notes provide complementary information to support the main document, or can be used for additional notes while working on a collaborative project. This article explains how to use margin notes in your LATEX document.
Margin notes provide complementary information to support the main document, or can be used for additional notes while working on a collaborative project. This article explains how to use margin notes in your LATEX document.
Margin notes provide complementary information to support the main document, or can be used for additional notes while working on a collaborative project. This article explains how to use margin notes in your LATEX document.

\end{document}

Output: enter image description here

  • it's not at all clear the intention of your section redefinition, the minipage will disable all the usual code latex uses in section headings to prevent page breaks after section heads and to control indentation of the following paragraph, as well as disabling the optional argument and star form of \section ? – David Carlisle Jan 25 '18 at 23:59
  • @DavidCarlisle without the redefinition, the section title will be centered over the text, not centered on the page. I need to section title to be centered on the page. – ShoeIace Jan 26 '18 at 0:02
  • you can make the heading come wherever you want but the minipage just breaks all latex's section heading code. So you want it centred over the combined left margin and text block? – David Carlisle Jan 26 '18 at 0:07
  • Apparently removing the mini-page worked. I don't know where in my scramble to get this thing working the mini-page came in and why it never occurred to me to remove it, but I'm glad you told me to. Thanks! – ShoeIace Jan 26 '18 at 0:10
  • 1
    @Au101 No. Just copy and pasted some content from one of the pages I was using as a resource to get some filler content. – ShoeIace Jan 26 '18 at 0:17
3

You don't really have to use adjustwidth: titlesec has tools for that: \titlespacing takes 3 arguments, and the first is for changing the left margin of titles. Here is how it goes:

\documentclass{article}

\usepackage[left=3.0in, right=1.0in, top=1.0in, bottom=1.0in, marginparwidth=2.0in, showframe]{geometry}
\usepackage[export]{adjustbox}
\usepackage{marginnote}
\usepackage{titlesec}

%\titleformat{command}[shape]{format}{label}{sep}{before code}[after code]
\titleformat{\section}[display]{\bfseries\Large\filcenter}{Section \thesection}{0ex}{}[]
\titlespacing*{\section}{-2in}{4.5ex}{2.5ex}

\begin{document}

\section{Introduction}

\subsection{Sub Section 1}

\subsubsection{Sub Sub Section 1}

Margin notes provide complementary information to support the main document, or can be used for additional notes while working on a collaborative project. This article explains how to use margin notes in your LATEX document.
Margin notes provide complementary information to support the main document, or can be used for additional notes while working on a collaborative project. This article explains how to use margin notes in your LATEX document.
Margin notes provide complementary information to support the main document, or can be used for additional notes while working on a collaborative project. This article explains how to use margin notes in your LATEX document.

\section{A First Section}

Some text. Some more text. Some more text.


\end{document} 

enter image description here

|improve this answer|||||
  • I like this because it removes the need to re-define the section command. Thanks! – ShoeIace Jan 26 '18 at 0:13
  • One never medits enough documentations! This is the first time I have to use this parameter ;o) – Bernard Jan 26 '18 at 0:15

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.