## LaTeX forum ⇒ LyX ⇒ Centering image on page

Information and discussion about LyX, a WYSIWYM editor, available for Linux, Windows and Mac OS X systems.
johnny7
Posts: 17
Joined: Fri Oct 24, 2014 12:25 pm

### Centering image on page

Hi,

In the appendix, I want to include several images, one image per page (imagine reproductions of a manuscript). Centering it horizontally works fine, but how can I vertically center the image on the page? I was unable to find an answer online, there must be a simple solution.

Thanks!

Edit: The question has indeed been asked before, but no answer was provided: viewtopic.php?f=45&t=16016

Edit2: Okay, placing \vspace*{\fill} before and after the image should do the deal! Sometimes one has to ask first before being able to find a solution for himself.

Stefan Kottwitz
Posts: 8792
Joined: Mon Mar 10, 2008 9:44 pm
Hi johnny,

no problem! Great to see that your question is quickly solved, an thanks for posting your solution.

By the way, for centering on the page the margins should be the same for top and bottom. The command aboves centers within the text area.

Stefan

johnny7
Posts: 17
Joined: Fri Oct 24, 2014 12:25 pm
Okay, maybe I was too quick to consider it solved. I was perfectly able to center one image on a page. However, oddly, several images added behind each other do not align. I tried it with and without a new page or a page break between each image. They are all identical with \vspace*{\fill} before and after the image. Why are they nevertheless positioned differently?

I am working with LyX but the code looks like this:

\newpage{}\begin{center}\vspace*{\fill}\includegraphics[width=15cm]{\string"image1".png}\vspace*{\fill}\par\end{center}

Stefan Kottwitz
Posts: 8792
Joined: Mon Mar 10, 2008 9:44 pm
The \vspace*{\fill} commands should be outside the center environment, so before \begin{center} and after \end{center}.

Stefan

johnny7
Posts: 17
Joined: Fri Oct 24, 2014 12:25 pm
Thanks! This didn't change anything though. I also noticed that it makes a difference if a comment section is added at the end or not (why?). Now all images are a bit too low on the page, that is the gap to the bottom is smaller, although the margins are set the same.

Stefan Kottwitz
Posts: 8792
Joined: Mon Mar 10, 2008 9:44 pm
Interesting! But there should be a simple explanation. Could you post a complete example? Either constructing it based on your document, or a reduced copy of your document without the actual text.

Stefan

johnny7
Posts: 17
Joined: Fri Oct 24, 2014 12:25 pm
Can you work with a lyx file? In this case I'll upload one.

Stefan Kottwitz
Posts: 8792
Joined: Mon Mar 10, 2008 9:44 pm
I don't have LyX on my notebook and I'm traveling. However, a pdfLaTeX export of the LyX file would be perfect too. It should behave exactly the same, and shows the LaTeX code generated by LyX.

Stefan

johnny7
Posts: 17
Joined: Fri Oct 24, 2014 12:25 pm
Okay, now, after I deleted the closing comment section, the last image is aligned with the first. They seem all placed a bit too low, is that right?
I've got another question for which I'll open another thread.
Edit: Well, the other question concerned hyphenation. My hyphenation rule did not work because \usepackage{babel} followed after \hyphenation{Renais-sance}. To put it behind I seem to have to include it as a TeX code in the LyX document itself instead of the preamble.

\documentclass[12pt,ngerman]{article}\usepackage{mathptmx}\usepackage[T1]{fontenc}\usepackage[latin9]{inputenc}\usepackage[a4paper]{geometry}\geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=2.5cm,rmargin=2.5cm}\usepackage{graphicx}\usepackage{setspace}\makeatletter%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.\usepackage{blindtext}\hyphenation{Renais-sance}\makeatother\usepackage{babel}\begin{document}\appendix\section{Anhang}\subsection{Test}\blindtext\subsection{Hyphenation}Renaissance Renaissance Renaissance Renaissance Renaissance RenaissanceRenaissance Renaissance Renaissance Renaissance Renaissance RenaissanceRenaissance Renaissance Renaissance Renaissance\newpage{} \vspace*{\fill}\begin{center}\includegraphics[width=15cm]{test}\par\end{center} \vspace*{\fill} \newpage{} \vspace*{\fill}\begin{center}\includegraphics[width=15cm]{test}\par\end{center} \vspace*{\fill} \newpage{} \vspace*{\fill}\begin{center}\includegraphics[width=15cm]{test}\par\end{center} \vspace*{\fill}\end{document}

Stefan Kottwitz