左对齐标题和蓝色背景,匹配样式

左对齐标题和蓝色背景,匹配样式

我正在尝试在 LaTeX 中复制期刊的标题样式,特别是如下所示的样式:

在此处输入图片描述

到目前为止我已经得到了这个:

\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}

看起来像这样:

在此处输入图片描述

我有几个问题:

  • 所有标题元素均未左对齐,我尝试使用该flushleft环境,但导致编译错误。

  • colorbox导致标题无法正确换行并延伸到右边距,而且似乎填充也稍微少一些。

上述问题该如何解决?

答案1

\colorbox不会跨行,除非您将内容放在\parbox/内minipage。因此,您可以将标题内容放在 内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}

另一种方法是使用tcolorbox(这里事情可能会变得更加奇特;-)...):

\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}

在此处输入图片描述

相关内容