Below is an MWE.



\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
\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{\vspace{-15mm}\fontsize{24pt}{10pt}\selectfont\textbf{A Minimum Working Example}} % Article title



\maketitle % Insert title

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


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

\lipsum[2-3] % Dummy text



\lipsum[7] % Dummy text



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?

enter image description here

  • 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

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


for your \colorsection:

enter image description here

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.

| improve this answer | |

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.