# Minor difference in width of column and text

Below is an MWE.

%---------------------------------------------------------------------
%   PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%---------------------------------------------------------------------

\documentclass[twoside]{article}

\usepackage{lipsum,xcolor}
\usepackage[hmarginratio=1:1,top=32mm,columnsep=20pt]{geometry} % Document margins
\usepackage{multicol} % Used for the two-column layout of the document
\usepackage{titlesec} % Allows customization of titles
\titleformat{\section}[block]{\large\scshape}{}{0pt}{\colorsection}{}
\renewcommand\thesection{}
\newcommand{\colorsection}[1]{\colorbox{blue!20}{\parbox{\columnwidth}{\thesection \centering #1}}}
\usepackage{fancyhdr} % Headers and footers
\pagestyle{fancy} % All pages have headers and footers

%----------------------------------------------------------------------------------------
%   TITLE SECTION
%----------------------------------------------------------------------------------------

\title{\vspace{-15mm}\fontsize{24pt}{10pt}\selectfont\textbf{A Minimum Working Example}} % Article title
\author{}
\date{}

%----------------------------------------------------------------------------------------

\begin{document}

\maketitle % Insert title

\thispagestyle{fancy} % All pages have headers and footers

%----------------------------------------------------------------------------------------
%   ARTICLE CONTENTS
%----------------------------------------------------------------------------------------

\begin{multicols}{2} % Two-column layout throughout the main article text

\section*{Introduction}
\lipsum[2-3] % Dummy text

%------------------------------------------------

\section*{Discussion}

\lipsum[7] % Dummy text

\end{multicols}

\end{document}


As you can see that there is a minor difference in width of the column and the width of the column text itself. How can I correct the discrepancy?

• Your title font choice doesn't work here - there is no 24pt font. Use something like \LARGE or \huge, or \Huge, depending on what's closest. See What point (pt) font size are \Large etc.? for a discussion on font sizes that are based on your default document class choice (10pt in your case). – Werner Dec 6 '15 at 7:53
• @Werner: Why shouldn't the code \fontsize{24pt}{10pt}\selectfont work ? I guess the O.P. uses vector fonts, as every one does nowadays. – Bernard Dec 6 '15 at 11:24
• @Bernard: The font is only available in certain sizes. You'll receive a LaTeX font warning "Size substitutions with differences up to 0.88pt have occurred." as the CM font is only available in 24.88pt, not 24pt. – Werner Dec 6 '15 at 12:17
• Even the opentype versions? And how does the lettrine package to scale fonts in an exact way? – Bernard Dec 6 '15 at 12:20

## 1 Answer

Your \colorboxes necessarily add a gap between the contents and the outer edge of the box. This width is called \fboxsep, since a \colorbox is an \fbox without any rules around it. As such, use

\newcommand{\colorsection}[1]{%
\colorbox{blue!20}{%
\makebox[\dimexpr\columnwidth-2\fboxsep]{#1}}}


for your \colorsection:

I've used \makebox[<width>]{<stuff>} instead of a \parbox, as the latter is not needed here. \makebox necessarily centres its contents.

Since \thesection is technically a no-op, I've removed it from the heading setting as well.