Theses, Books, Title pagesCentering oversize image in text column

Classicthesis, Bachelor and Master thesis, PhD, Doctoral degree
Post Reply
Serpenthelm
Posts: 7
Joined: Mon Jun 04, 2012 3:50 pm

Centering oversize image in text column

Post by Serpenthelm »

I'm using the masters-doctoral-thesis template and I'm trying to center a slightly oversize png image. I'm compiling with pdflatex.

The image is too big to fit the column, but is there a way to make it centered respective to the column text, instead of it simply go out to the right?

Image

This is the code

Code: Select all

\chapter{The power grid}
\label{Chapter2}
\lhead{Chapter 2. \emph{The power grid}}

\begin{figure}[]
	\centering
	\includegraphics[scale=1]{Images/misc/PJM_Daily_Demand.png}
	\caption{Average daily and hourly demand in the transmission system operated by...}
	\label{fig:daily_demand}
\end{figure}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Centering oversize image in text column

Post by cgnieder »

You have two options:
  • scale the image so it fits
  • put the picture in a box that fits

Code: Select all

\documentclass{article}
\usepackage{graphicx}
\usepackage{showframe}% show page dimensions
\begin{document}
\begin{figure}
\includegraphics[width=\linewidth]{Figure_centering.png}
\end{figure}
\begin{figure}
  \makebox[\linewidth][c]{\includegraphics{Figure_centering.png}}
\end{figure}
\end{document}
The line \makebox[\linewidth][c]{...} puts its contents in a box of width \linewidth and centers its contents (c). The second optional argument [c] isn't necessary as this is the default alignment. \makebox[\linewidth]{...} would suffice.

Regards
site moderator & package author
Serpenthelm
Posts: 7
Joined: Mon Jun 04, 2012 3:50 pm

Centering oversize image in text column

Post by Serpenthelm »

Putting the picture in a box did the trick.
The box can grow much wider than the text column, and that is what I wanted.
However, \includegraphics[width=\linewidth] did not help.

Thank you.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Centering oversize image in text column

Post by cgnieder »

Serpenthelm wrote:However, \includegraphics[width=\linewidth] did not help.
“Did not help” is a rather vague description. I know that this proposal doesn't center the overwide figure with respect to the text body. Instead it scales the figure down so it fits exactly. While this might be not the solution you looked for it still might come in handy with another figure some day :)

(Besides: personally I prefer figures not to be wider than the text but that is a matter of taste I guess.)

Regards
site moderator & package author
Post Reply