4

I'm trying to create a document according some brand guidelines which require the use of angled and coloured section headings.

I have the colours working using the xcolor and sectsty packages, but cannot find how to rotate the headings.

I've also tried using the rotating package. It works fine for ordinary text, but it throws an error when I try to use it for a section.

Here's my working example:

\documentclass{article}

\usepackage{helvet}
\usepackage{xcolor}
    \definecolor{my-green}{RGB}{134,162,11}

% Section Styling
\usepackage{sectsty}
    \sectionfont{\huge \color{my-green}}

\begin{document}
    \section{I'd like to rotate this}
\end{document}

EDIT

Based on the answers below, here is the code I eventually used to solve the problem:

\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage[explicit]{titlesec}
\usepackage{graphicx}

\usepackage{xcolor}
    \definecolor{scout-green}{RGB}{134,162,11}
    \definecolor{scout-purple}{RGB}{77,33,119}

\newif\ifwithrotation

\newcommand \basictitlebeforecode[1] {
    \parbox[t]{\dimexpr\textwidth\relax}{\raggedright#1}
}

\newcommand \fulltitlebeforecode[1] {
    \ifwithrotation
        \rotatebox{6}{\basictitlebeforecode{#1}}
    \else
        \basictitlebeforecode{#1}
    \fi
}

\usepackage[explicit]{titlesec}
    \titleformat{\section}[hang]
        {\Huge\sffamily\bfseries\color{scout-green}}
        {}{0em}
        {\fulltitlebeforecode{#1}}

    \titleformat{\subsection}[hang]
        {\LARGE\sffamily\bfseries\color{scout-purple}}
        {}{0em}
        {\fulltitlebeforecode{#1}}

\begin{document}

    \section{Ordinary Short Section}
    \subsection{Ordinary Short Subsection}

    \withrotationtrue
        \section{Rotated Short Section}
        \subsection{Rotated Short Subsection}
    \withrotationfalse

    \section{This is a purposely long section title that extends on more than one line}
    \subsection{This is a purposely long subsection title that extends on more than one line}

    \withrotationtrue
        \section{This is a purposely long rotated section title that extends on more than one line}
        \subsection{This is a purposely long rotated subsection title that extends on more than one line}
    \withrotationfalse

\end{document}

enter image description here

  • 1
    Can you post an image of the layout you’re trying to achieve? – Ant Oct 16 '14 at 10:50
  • I'm trying to create some brochures and leaflets which follow the brand guidelines for UK Scouting: members.scouts.org.uk/comms_centre/zip/Brand_Guidelines.pdf The first page shows an example of the rotated text for headings – Owen Oct 16 '14 at 10:54
  • 2
    The simplest approach might be to use something like \section*{\rotatebox{20}{1. I'd like to rotate this}}. (rotatebox is from the graphicx pacakge.) – Thruston Oct 16 '14 at 10:57
  • @Thruston that works nicely! I may just use it in a newcommand – Owen Oct 16 '14 at 11:00
  • 1
    You'll be able to do that with the titlesec and the graphicx or rotating packages. – Bernard Oct 16 '14 at 11:00
4

Here is an example of what can be done using titlesecand graphicx. See the documentation of titlesec, in particular for spacing.

\documentclass{book}
\usepackage[a4paper, showframe]{geometry}
\usepackage[explicit]{titlesec}
\usepackage{graphicx}

\usepackage{xcolor}
    \definecolor{my-green}{RGB}{134,162,11}

\usepackage{mathtools}

\titleformat{\section}[hang]{\huge\sffamily\bfseries\color{my-green}}{}{0em}{\rotatebox{9}{\arabic{section}.\enspace\parbox[t]%
{\dimexpr\linewidth-2em\relax}{\raggedright#1}}}
\pagestyle{plain}

\begin{document}

  \section{This is a short title}
  This is a paragraph.

  \section{This is a purposely long title that extends on more than one line}
  This is a paragraph.

\end{document} 

enter image description here

  • yes a rather more complete example than mine:-) – David Carlisle Oct 16 '14 at 12:04
  • Not used titlesec before (never had the need for my own stuff), but this looks like the way to go. I should be able to define two section classes - with and without the rotation – Owen Oct 16 '14 at 12:25
  • 1
    @ Owen: Maybe you could introduce a boolean (withrot, say) and make the last argument a command that depends on the value of this boolean. It shouldn't be too hard with the explicit option of titlesec. You also can create new sectioning levels. – Bernard Oct 16 '14 at 19:41
  • @Bernard I managed to create two classes and get it all working. The boolean sounds better. I'll have to read up on how to do that. (Much more interesting than actually writing the content for this leaflet)! – Owen Oct 17 '14 at 9:51
  • @Bernard thanks again for the hint. Much nicer code now with a boolean variable and no need for a separate titleclass – Owen Oct 17 '14 at 10:30
4

enter image description here

The underlying \@startsection mechanism LaTeX uses for headings is designed to allow the last command in the font specification to be a command that takes an argument, to allow rotation, uppercasing, etc. this facility falls through to the secsty package.

\documentclass{article}

\usepackage{helvet}
\usepackage{xcolor,graphicx}
    \definecolor{my-green}{RGB}{134,162,11}

% Section Styling
\usepackage{sectsty}
    \sectionfont{\huge \color{my-green}\rotatebox{10}}

\begin{document}
\tableofcontents

    \section{I'd like to rotate this}
    \section{I'd like to rotate this as well}
\end{document}
  • Not sure I get the 'egreg' bit, but that's an elegant solution to an inelegant problem! – Owen Oct 16 '14 at 11:46
  • Don't worry about that reference, I may remove it in a bit (just banter between the regulars here) – David Carlisle Oct 16 '14 at 11:48
  • @Owen updated with a bit of explanation – David Carlisle Oct 16 '14 at 11:51

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.