# Center body and left margin in page

I'm using the titlesec package to put section titles to the left of their body, but I'd like for the entire page to appear centered. That is, I'd like for the space from the far left of the page to the beginning of the title equal the space from the end of the text body to the far right of the page.

How can I accomplish this?

Relevant WIP code:

\titleformat{\section}[leftmargin]{\raggedright\scshape}{}{0pt}{}
\titlespacing*{\section}{2.5cm}{*2.5}{0.5cm}
\titleformat{\subsection}{\bfseries}{}{0pt}{}
\titlespacing*{\subsection}{0pt}{*2}{*1}


Edit: As @cmhughes pointed out, I can manually adjust the margins with the geometry package to align the page properly. However, things like the title of the page look skewed, since they are centered with respect to the body. Is there any way I can center a different element with respect to the page?

-
Have you tried using the geometry package to tweak the margins? e.g \usepackage[left=4cm]{geometry} –  cmhughes Dec 19 '11 at 4:51
Nice, that helps. Is there anyway I can have other elements centered over both of them (the left margin and the body)? For example, the title? Adding this question to the OP. –  awegawef Dec 19 '11 at 5:00
You could wrap the title in something like \begin{adjustwidth}{-3cm}{}\begin{center}... \end{center}\end{adjustwidth} where adjustwidth is from the changepage package –  cmhughes Dec 19 '11 at 5:07
@awegawef: My answer seems to address your original question, while the edit seems to have confused the issue a little. Am I still on target with my answer? –  Werner Dec 19 '11 at 5:13
@Werner, yep! Your thorough answer resolves my original question. The comment posted by cmhughes helps me with my second. –  awegawef Dec 19 '11 at 5:16

Using titlesec, you set the title spacing to be 2.5cm+0.5cm (or 30mm) from the left margin of the text. As such, specifying the left and right margins, using geometry, as

\usepackage{geometry}% http://ctan.org/pkg/geometry
\newcommand{\mygeometry}[1]{%
\geometry{right=#1,left=\dimexpr#1+30mm\relax}% Set new geometry
}
\mygeometry{25mm}% 25mm left/right margins


will give you 25mm left/right margins. You can specify any known dimension <len> in \mygeometry{<len>}. If you modify the spacing of your titles, would need to modify the 30mm dimension in \mygeometry as well.

Here is a minimal working example highlighting the above procedure and shows the first two pages of output:

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{geometry}% http://ctan.org/pkg/geometry
\newcommand{\mygeometry}[1]{%
\geometry{right=#1,left=\dimexpr#1+30mm\relax}% Set new geometry
}
\mygeometry{25mm}% 25mm left/rightmargins
\usepackage{titlesec}% http://ctan.org/pkg/titlesec
\titleformat{\section}[leftmargin]{\raggedright\scshape}{}{0pt}{}
\titlespacing*{\section}{2.5cm}{*2.5}{0.5cm}
\titleformat{\subsection}{\bfseries}{}{0pt}{}
\titlespacing*{\subsection}{0pt}{*2}{*1}
\begin{document}
\section{First section} \lipsum[1]
\subsection{First subsection} \lipsum[2]
\subsection{Second subsection} \lipsum[3]
\subsection{Third subsection} \lipsum[4]
\subsection{Last subsection} \lipsum[5]
\section{Second section} \lipsum[1]
\subsection{First subsection} \lipsum[2]
\subsection{Second subsection} \lipsum[3]
\subsection{Third subsection} \lipsum[4]
\subsection{Last subsection} \lipsum[5]
\section{Last section} \lipsum[1]
\subsection{First subsection} \lipsum[2]
\subsection{Second subsection} \lipsum[3]
\subsection{Third subsection} \lipsum[4]
\subsection{Last subsection} \lipsum[5]
\end{document}


lipsum was only used to provide dummy text.

-