Graphics, Figures & TablesGraphic not central on 2 colunm environment.

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
sw3quant
Posts: 76
Joined: Tue Nov 02, 2010 11:40 pm

Graphic not central on 2 colunm environment.

Post by sw3quant »

I have a two colunm environment. I try and load a image, and it appears distinctly off-centre for the col it is in. How can I ensure its central?

My MWE is below. I have included all the packages, incase its a package interaction issue.


Code: Select all

%% This is file `elsarticle-template-2-harv.tex',
%%
%% Copyright 2009 Elsevier Ltd
%%
%% This file is part of the 'Elsarticle Bundle'.
%% ---------------------------------------------
%%
%% It may be distributed under the conditions of the LaTeX Project Public
%% License, either version 1.2 of this license or (at your option) any
%% later version.  The latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.2 or later is part of all distributions of LaTeX
%% version 1999/12/01 or later.
%%
%% The list of all files belonging to the 'Elsarticle Bundle' is
%% given in the file `manifest.txt'.
%%
%% Template article for Elsevier's document class `elsarticle'
%% with harvard style bibliographic references
%%
%% $Id: elsarticle-template-2-harv.tex 155 2009-10-08 05:35:05Z rishi $
%% $URL: http://lenova.river-valley.com/svn/elsbst/trunk/elsarticle-template-2-harv.tex $
%%
%\documentclass[preprint,authoryear,8pt]{elsarticle}

%% Use the option review to obtain double line spacing
%% \documentclass[authoryear,preprint,review,12pt]{elsarticle}

%% Use the options 1p,twocolumn; 3p; 3p,twocolumn; 5p; or 5p,twocolumn
%% for a journal layout:
% \documentclass[final,authoryear,1p,times]{elsarticle}
%% \documentclass[final,authoryear,1p,times,twocolumn]{elsarticle}
 \documentclass[final,authoryear,3p,times,twocolumn]{elsarticle}
%% \documentclass[final,authoryear,3p,times,twocolumn]{elsarticle}
%% \documentclass[final,authoryear,5p,times]{elsarticle}
%% \documentclass[final,authoryear,5p,times,twocolumn]{elsarticle}

%% if you use PostScript figures in your article
%% use the graphics package for simple commands
%% \usepackage{graphics}
%% or use the graphicx package for more complicated commands
%% \usepackage{graphicx}
%% or use the epsfig package if you prefer to use the old commands
%% \usepackage{epsfig}

%% The amssymb package provides various useful mathematical symbols
\usepackage{amssymb}
%% The amsthm package provides extended theorem environments
%% \usepackage{amsthm}

%% The lineno packages adds line numbers. Start line numbering with
%% \begin{linenumbers}, end it with \end{linenumbers}. Or switch it on
%% for the whole article with \linenumbers after \end{frontmatter}.
%% \usepackage{lineno}

%% natbib.sty is loaded by default. However, natbib options can be
%% provided with \biboptions{...} command. Following options are
%% valid:

%%   round  -  round parentheses are used (default)
%%   square -  square brackets are used   [option]
%%   curly  -  curly braces are used      {option}
%%   angle  -  angle brackets are used    <option>
%%   semicolon  -  multiple citations separated by semi-colon (default)
%%   colon  - same as semicolon, an earlier confusion
%%   comma  -  separated by comma
%%   authoryear - selects author-year citations (default)
%%   numbers-  selects numerical citations
%%   super  -  numerical citations as superscripts
%%   sort   -  sorts multiple citations according to order in ref. list
%%   sort&compress   -  like sort, but also compresses numerical citations
%%   compress - compresses without sorting
%%   longnamesfirst  -  makes first citation full author list
%%
%% \biboptions{longnamesfirst,comma}

% \biboptions{}

%%%%%%%%%%%
\usepackage[T1]{fontenc}
\usepackage{prettyref}
\usepackage{url}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{xcolor}
\usepackage{amsfonts}
\usepackage{nicefrac}
\usepackage{capt-of}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{float}
\usepackage{xspace}
\usepackage{algorithmwh}
\usepackage{verbatim}
\usepackage{mathdots}
\usepackage{bm}
\usepackage{amsmath,amssymb}
% for GNUMERIC
%\usepackage{ucs}
%%\usepackage{utf8}{inputenc}
%\usepackage[latin1]{inputenc}


\usepackage{array}
%\newcommand{\head}[2]{\multicolumn{1}{>{\centering\arraybackslash}p{#1}|}{\textbf{#2}}}

\newcommand{\head}[1]{\textbf{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\usepackage{amsfonts}
\newcommand{\tickYes}{\checkmark}
\usepackage{pifont}
\newcommand{\tickNo}{\hspace{1pt}\ding{55}}


\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}


\usepackage{rotating} %table in landscape

\usepackage{color}
\usepackage{array}
\usepackage{longtable}
\usepackage{calc}
\usepackage{multirow}
\usepackage{hhline}
\usepackage[framed,numbered]{mcode}
\usepackage{ifthen}
\usepackage{lscape}
\def\inputGnumericTable{}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\newcommand{\lyxline}[1][1pt]{%
  \par\noindent%
  \rule[.5ex]{\linewidth}{#1}\par}
\newcommand{\noun}[1]{\textsc{#1}}
%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}
%%%%%%%%%HUGHs MACROS%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\newcommand{\argmax}{\operatornamewithlimits{argmax}}
%\newcommand{\max}{\operatornamewithlimits{max}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\newcommand{\x}{\mathrm{x}}
%\newcommand{\bx}{\bm{\x}}
\newcommand{\z}{\mathrm{z}}
\newcommand{\bz}{\bm{\z}}
\newcommand{\ert}[1]{\emph{\textcolor{red}{#1}}}
\newcommand{\cn}{\textcolor{blue}{$^{[\text{\emph{citation needed}}]}$}}
\newcommand{\todo}[1]{\textcolor{red}{[TO DO: {#1}]}}
\newcommand{\draft}[1]{\textcolor{blue}{[DRAFT: {#1}]}}
\newcommand{\checkme}[1]{\textcolor{Maroon}{{#1} (check!)}}
\newcommand{\maybe}[1]{\textcolor{OliveGreen}{Maybe: {#1} (?)}}
\newcommand{\expect}[1]{\mathbb{E}\left({#1}\right)}
\newcommand{\expectnb}[1]{\mathbb{E}\text{ }{#1}}
\newcommand{\cov}{\text{cov}}
\newcommand{\st}{\textsuperscript{st}\ }
\newcommand{\nd}{\textsuperscript{nd}\ }
\newcommand{\rd}{\textsuperscript{rd}\ }
\newcommand{\thh}{\textsuperscript{th}\ }
\newcommand{\ith}{$i$\thh}
\usepackage{cite}
\usepackage{lettrine}

\usepackage[active]{srcltx}
\newrefformat{tab}{Table \ref{#1}}
\newrefformat{fig}{Fig. \ref{#1}}
\makeatother
\usepackage{hyperref} %this needs to go last because of package interaction

%%%%%%%%%%%%%


\begin{document}

\begin{frontmatter}






\begin{figure}[H]
    \begin{center}
        {\includegraphics[width=3.5in,keepaspectratio]{images/blah}}
        \caption{blah}
        \label{blah}
    \end{center}
\end{figure}

\end{document}

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Graphic not central on 2 colunm environment.

Post by Stefan Kottwitz »

sw3quant wrote:I have included all the packages, incase its a package interaction issue.
You could see if it's an interaction issue: remove packages and check if the problem persists. Post a Infominimal working example. Sorry, I cannot help you this way, I don't have the packages algorithmwh and mcode of this ton of packages. And I don't like to read about 80 lines of comments before the real code.

Testing is not possible since your example doesn't show the text in a column which you would like to compare with the image (which you did not post).

Just understand, this is not a personal support place like "throwing unprepared large amounts of code, and get specific help", you can expect this if you get paid support by TeX consultants. This is a public forum where people read and write about hopefully interesting problems - in their personal free time.

If you would prepare your question well, nice to read and to test, you could expect to get a well prepared answer with a tested solution.

Stefan
LaTeX.org admin
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Graphic not central on 2 colunm environment.

Post by localghost »

I expressly agree with Stefan. You should always check your examples for functionality and minimal content to give an adequate problem description. And as far as I remember this is not the first time that you are told to do so.

And there are some more concerns about the code you presented.
  • The frontmatter environment has a beginning, but no end. Hence the example won't compile.
  • You try to include a graphic that shall be 3.5in wide. It is very unlikely in a two-column environment that \columnwidth is big enough by default.

Thorsten
Post Reply