4

I'm trying to replicate a journal's titling style in LaTeX specifically one that looks like this:

enter image description here

So far I've got this:

\documentclass[11pt,a4paper,twoside, twocolumn]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[UKenglish]{babel}
\usepackage[UKenglish]{isodate}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{lmodern}
\usepackage{bm}
\usepackage[usenames,dvipsnames]{color}
\definecolor{docblue}{RGB}{0,116,178}   
\definecolor{docgrey}{RGB}{166,168,170} 

\usepackage{titling}
\setlength{\droptitle}{-9em} 

\title{\colorbox{docblue}{\LARGE \textbf{\color{white}{Detection and diagnosis of H7N9 \& MERS-CoV by RT-PCR}}}}
\author{ \textbf{\textsf{J Smith}$\bm{^{1}}$} \\ \color{docgrey}{\textbf{1. Institute, City, Country}}}
\date{}
\usepackage{microtype}

\begin{document}

\maketitle

\end{document}

Which looks like this:

enter image description here

I have a few issues:

  • None of the title elements are aligned left, I tried using the flushleft environment however it caused compile errors.

  • colorbox causes the title to not wrap correctly and extend over the right margin, it also appears to have slightly less padding too.

How can the above be solved?

Ben
  • 1,229

1 Answers1

7

\colorbox won't break across lines unless you put the contents inside a \parbox / minipage. Hence you may put the title contents inside a parbox.

\documentclass[11pt,a4paper,twoside, twocolumn]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{bm}
\usepackage[usenames,dvipsnames]{xcolor}
\definecolor{docblue}{RGB}{0,116,178}
\definecolor{docgrey}{RGB}{166,168,170}

\usepackage{titling}
\setlength{\droptitle}{-9em} 

\pretitle{\par}
\DeclareRobustCommand{\titlething}{\colorbox{docblue}{%
\LARGE \bfseries\textcolor{white}{\parbox{\dimexpr\linewidth-2\fboxsep\relax}{Detection and diagnosis of H7N9 \& MERS-CoV by RT-PCR}}}}
\title{\titlething}
\posttitle{\par}
\preauthor{\begin{flushleft}}
\author{ \textbf{\textsf{J Smith}$\bm{^{1}}$} \\ \color{docgrey}{\textbf{1. Institute, City, Country}}}
\postauthor{\end{flushleft}}
\date{}
\usepackage{microtype}

\begin{document}

\maketitle

\end{document}

Another approach using tcolorbox (things can get fancier here ;-)...):

\documentclass[11pt,a4paper,twoside, twocolumn]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{bm}
\usepackage[usenames,dvipsnames]{xcolor}
\definecolor{docblue}{RGB}{0,116,178}
\definecolor{docgrey}{RGB}{166,168,170}
\usepackage{titling}
\setlength{\droptitle}{-9em}
\usepackage{tcolorbox}


\pretitle{\par}
\DeclareRobustCommand{\titlething}{%
\begin{tcolorbox}[   %% Adjust the following parameters at will.
        left=0pt,
        right=0pt,
        top=0pt,
        bottom=0pt,
        colback=docblue,
        colframe=docblue,
        width=\dimexpr\textwidth\relax,
        enlarge left by=0mm,
        boxsep=5pt,
        arc=0pt,outer arc=0pt,
        ]
        \LARGE \bfseries\textcolor{white}{Detection and diagnosis of H7N9 \& MERS-CoV by RT-PCR}
\end{tcolorbox}
}
\title{\titlething}
\posttitle{\par}
\preauthor{\begin{flushleft}}
\author{ \textbf{\textsf{J Smith}$\bm{^{1}}$} \\ \color{docgrey}{\textbf{1. Institute, City, Country}}}
\postauthor{\end{flushleft}}
\date{}
\usepackage{microtype}

\begin{document}

\maketitle

\end{document}

enter image description here

  • That works and it compiles a document that looks just fine but it does give me the compile error: ! Argument of \reserved@a has an extra }. and ! Paragraph ended before \reserved@a was complete. both on the line ending the tcolorbox declaration.. – Ben Oct 12 '13 at 22:45
  • Also any idea how to get the author and institute line to left align? – Ben Oct 12 '13 at 22:45
  • Once again everything compiles just fine, but I do get an error '! LaTeX Error: Option clash for package xcolor.' from the line \definecolor{docblue}{RGB}{0,116,178} interestingly... – Ben Oct 12 '13 at 23:24
  • Ben Put PassOptionsToPackage{usenames,dvipsnames}{xcolor} before \documentclass{...} and remove \usepackage[usenames,dvipsnames]{color} –  Oct 12 '13 at 23:27
  • That worked perfectly, thanks for your time and effort Harish! – Ben Oct 12 '13 at 23:33
  • @Ben You are welcome. Glad it worked. –  Oct 12 '13 at 23:35