LyX ⇒ Centering image on page
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: http://latex.org/forum/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.
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: http://latex.org/forum/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.
NEW: TikZ book now 40% off at Amazon.com for a short time.

- Stefan Kottwitz
- Site Admin
- Posts: 10340
- Joined: Mon Mar 10, 2008 9:44 pm
Centering image on page
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
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
LaTeX.org admin
Centering image on page
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:
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
- Site Admin
- Posts: 10340
- Joined: Mon Mar 10, 2008 9:44 pm
Centering image on page
The
Stefan
\vspace*{\fill}
commands should be outside the center environment, so before \begin{center}
and after \end{center}
.Stefan
LaTeX.org admin
Centering image on page
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
- Site Admin
- Posts: 10340
- Joined: Mon Mar 10, 2008 9:44 pm
Centering image on page
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
Stefan
LaTeX.org admin
Centering image on page
Can you work with a lyx file? In this case I'll upload one.
- Stefan Kottwitz
- Site Admin
- Posts: 10340
- Joined: Mon Mar 10, 2008 9:44 pm
Centering image on page
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
Stefan
LaTeX.org admin
Centering image on page
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.
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.
Code: Select all
\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 Renaissance
Renaissance Renaissance Renaissance Renaissance Renaissance Renaissance
Renaissance 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
- Site Admin
- Posts: 10340
- Joined: Mon Mar 10, 2008 9:44 pm
Centering image on page
Good that you found it! I'm off for 10 hours now, flying to Miami. 
Stefan

Stefan
LaTeX.org admin