LaTeX forum ⇒ LyXCentering 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

Postby johnny7 » Wed Dec 13, 2017 6:52 pm

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.

User avatar
Stefan Kottwitz
Site Admin
Posts: 9091
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Wed Dec 13, 2017 10:10 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
Site admin

johnny7
Posts: 17
Joined: Fri Oct 24, 2014 12:25 pm

Postby johnny7 » Fri Dec 15, 2017 12:41 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}

User avatar
Stefan Kottwitz
Site Admin
Posts: 9091
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Fri Dec 15, 2017 7:42 pm

The \vspace*{\fill} commands should be outside the center environment, so before \begin{center} and after \end{center}.

Stefan
Site admin

johnny7
Posts: 17
Joined: Fri Oct 24, 2014 12:25 pm

Postby johnny7 » Sun Dec 17, 2017 1:20 am

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.

User avatar
Stefan Kottwitz
Site Admin
Posts: 9091
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Sun Dec 17, 2017 8:08 am

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
Site admin

johnny7
Posts: 17
Joined: Fri Oct 24, 2014 12:25 pm

Postby johnny7 » Sun Dec 17, 2017 10:47 am

Can you work with a lyx file? In this case I'll upload one.

User avatar
Stefan Kottwitz
Site Admin
Posts: 9091
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Sun Dec 17, 2017 10:55 am

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
Site admin

johnny7
Posts: 17
Joined: Fri Oct 24, 2014 12:25 pm

Postby johnny7 » Sun Dec 17, 2017 11:40 am

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.

  1. \documentclass[12pt,ngerman]{article}
  2. \usepackage{mathptmx}
  3. \usepackage[T1]{fontenc}
  4. \usepackage[latin9]{inputenc}
  5. \usepackage[a4paper]{geometry}
  6. \geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=2.5cm,rmargin=2.5cm}
  7. \usepackage{graphicx}
  8. \usepackage{setspace}
  9. \makeatletter
  10. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
  11. \usepackage{blindtext}
  12. \hyphenation{Renais-sance}
  13. \makeatother
  14. \usepackage{babel}
  15. \begin{document}
  16. \appendix
  17. \section{Anhang}
  18. \subsection{Test}
  19. \blindtext
  20. \subsection{Hyphenation}
  21. Renaissance Renaissance Renaissance Renaissance Renaissance Renaissance
  22. Renaissance Renaissance Renaissance Renaissance Renaissance Renaissance
  23. Renaissance Renaissance Renaissance Renaissance
  24. \newpage{}
  25.  
  26. \vspace*{\fill}
  27. \begin{center}
  28. \includegraphics[width=15cm]{test}
  29. \par\end{center}
  30.  
  31. \vspace*{\fill}
  32.  
  33. \newpage{}
  34.  
  35. \vspace*{\fill}
  36. \begin{center}
  37. \includegraphics[width=15cm]{test}
  38. \par\end{center}
  39.  
  40. \vspace*{\fill}
  41.  
  42. \newpage{}
  43.  
  44. \vspace*{\fill}
  45. \begin{center}
  46. \includegraphics[width=15cm]{test}
  47. \par\end{center}
  48.  
  49. \vspace*{\fill}
  50. \end{document}

User avatar
Stefan Kottwitz
Site Admin
Posts: 9091
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Sun Dec 17, 2017 12:39 pm

Good that you found it! I'm off for 10 hours now, flying to Miami. :)

Stefan
Site admin


Return to “LyX”

Who is online

Users browsing this forum: No registered users and 3 guests