# Remove whitespace above section title with image formatted with leftmargin

I am trying to remove the whitespace above a title that is formatted with leftmargin and that also has an image as part of it. The problem is very similar to this question, but the solution there does not work for me and it is not using leftmargin. There are a variety of other similar questions, but none that I can find with solutions to this particular situation.

When I remove the leftmargin formatting the space disappears.

My code is as follows. I would welcome any feedback as to whether there is a better way of achieving the same result (with a wide left margin).

\documentclass[a4paper]{article}

\usepackage[document]{ragged2e}
\usepackage{graphicx,titlesec,lipsum}
\usepackage[vmargin=0.8cm,hmargin={8.3cm,0.8cm},showframe]{geometry}

% Unrelated: how do you include parameters to commands in \titleformat
\newcommand{\includerotate}[1]{\includegraphics[angle=180,origin=c]{#1}}

\titleformat{\section}[leftmargin]
{\huge}
{}
{0em}
{}
[\hspace{-7.5cm}\includerotate{3_lines.pdf}\\]

\titlespacing{\section}
{0cm}{0pt}{7.5cm}

\begin{document}
\section{service overview}
\lipsum[1-2]
\end{document}


Which produces the following document. The whitespace that I am trying to remove is between the top margin and the coloured line. Here is a link to 3_lines.pdf if you want to compile the code.

• Impossible to compile your code: 3_lines.pdf not found. – Bernard Apr 3 '14 at 13:18
• @Bernard - okay, I've edited the question and added a link to that file. – abeverley Apr 3 '14 at 13:26

The spacing comes from the \huge in the format argument - it causes an ordinary strut to be inserted before the title is set. Instead you can use the "before code" argument of \titleformat to set the font size and also to place your graphic rule. I would also suggest that the title is placed in a narrow column raggedright, rather than in a zero width column, with overfull boxes:

\documentclass[a4paper]{article}

\usepackage[document]{ragged2e}
\usepackage{graphicx,titlesec}
\usepackage[vmargin=0.8cm,hmargin={8.3cm,0.8cm},showframe]{geometry}

\newcommand{\includerotate}[1]{\includegraphics[angle=180,origin=c,viewport=0
12 550 12]{#1}}

\titleformat{\section}[leftmargin]
{}
{}
{0em}
{\rlap{\includerotate{3_lines.pdf}}\endgraf\vspace{-15pt}\filright\huge}
[\strut]
\titlespacing{\section}
{3cm}{2ex plus 0.5ex minus 0.2ex}{4.5cm}

\usepackage{lipsum} %for dummy text
\usepackage[latin]{babel} %with correct hyphenation

\begin{document}
\section{service overview}
\lipsum[1-2]

\section{other details and material}
\lipsum[3-4]
\end{document}


The before prints the rule, in a box that has zero width via \rlap. It then starts a new paragraph, \par will not work here, but \endgraf is sufficient. The paragraph is set with titlesecs version of \raggedright, namely \filright, and the \huge size is chosen. The spacing has been changed so the title is set in a column 3cm wide, and vertical spacing has been added before the title.

My solution consists in considering your coloured rule as a label for the section title, rather than something you add after the section title has been written With the optional arguments of \raisebox, you can make LaTeX believe it has no height,no width. So I don't have to include, rotate, &c. any graphics file; the rule is drawn, when the section happens on top of page,just under the top limit of the test area.

Here is the code:

\documentclass[a4paper]{article}

\usepackage[document]{ragged2e}
\usepackage{graphicx,lipsum}
\usepackage[explicit]{titlesec}
\usepackage[x11names]{xcolor}
\usepackage[vmargin=0.8cm,hmargin={8.3cm,0.8cm},reversemarginpar, showframe]{geometry}

\titleformat{\section}[leftmargin]
{\huge}
{\raisebox{0.575\baselineskip}[0pt][0pt]{\color{HotPink4}\rule{7cm}{3pt}\hspace{14.25pt}\rule{\textwidth}{3pt}}}
{0em}
{#1}
%[\hspace{-7.5cm}\includerotate{3_lines.pdf}\\]
%[\includegraphics{3_lines.pdf}\\]%
\titlespacing{\section}
{0cm}{1.5\baselineskip}{7.5cm}

\begin{document}
\section{service overview}
\lipsum[1-10]
\section{service overview 2}
\lipsum[11-15]
\end{document}


and the result:

To answer your subsidiary question: you can very simply use one parameter with \titleformat, which is the section title, if you load titlesec with the explicit option. But maybe, you would like to pass other parameters?

• Thanks for this - it works well. The only disadvantage for me is that I am using the same styling for a TOC list, which caused problems as the title of the TOC has no label and therefore didn't display the line. However, I did end up drawing my own line (with shading) and used the raisebox idea to move it into place. – abeverley Apr 4 '14 at 13:28