TeX - LaTeX Asked by Rahn on February 21, 2021
This is my original document:
-------------------
|sec 1 |
|----- |
||fig| |
|----- |
| |
| |
| page1 |
-------------------
I’m hoping to position the figure to the center of the page, but after adding [p]
to begin{figure}[p]
, I got 2 pages:
-------------------
|sec 1 |
| |
| |
| |
| |
| |
| page1 |
-------------------
-------------------
| |
| |
| ----- |
| |fig| |
| ----- |
| |
| page2 |
-------------------
Is it possible to position the image in the center of the page even with other contents, like this?
-------------------
|sec 1 |
| |
| ----- |
| |fig| |
| ----- |
| |
| page1 |
-------------------
Right now let’s assume "other content" is simply the section title.
The only solution I have now is to measure the vertical space brought by the section title, and then compensate the same length at the bottom of the page and use two vfill
to center the figure vertically. But can it be done easier?
Code to get started:
documentclass{article}
usepackage[demo]{graphicx}
setlength{parindent}{0pt}
begin{document}
section*{sec 1}
begin{figure}[p]
centering
includegraphics{noimage}
end{figure}
end{document}
You can use tikz for that. I assume you wanted the figure + its caption centred.
documentclass{article}
usepackage[demo]{graphicx}
setlength{parindent}{0pt}
usepackage{lipsum}
usepackage{tikz}
usetikzlibrary{positioning}
usepackage{capt-of}
begin{document}
section*{sec 1}
lipsum[1]
begin{tikzpicture}[inner sep=0pt, overlay, remember picture]
node at (current page.center) {begin{tikzpicture}
node (fig) {includegraphics{noimage}};
node [below=belowcaptionskip of fig,text width=linewidth] {captionof{figure}{Caption}label{fig}};
end{tikzpicture}};
end{tikzpicture}
end{document}
If you want only the picture at page centre, we can remove the second tikzpicture:
documentclass{article}
usepackage[demo]{graphicx}
setlength{parindent}{0pt}
usepackage{lipsum}
usepackage{tikz}
usetikzlibrary{positioning}
usepackage{capt-of}
begin{document}
section*{sec 1}
lipsum[1]
begin{tikzpicture}[inner sep=0pt, overlay, remember picture]
node (fig) at (current page.center) {includegraphics{noimage}};
node [below=belowcaptionskip of fig,text width=linewidth] {captionof{figure}{Caption}label{fig}};
end{tikzpicture}
end{document}
For the subfigures, I use a matrix:
documentclass{article}
usepackage[demo]{graphicx}
setlength{parindent}{0pt}
usepackage{lipsum}
usepackage{tikz}
usetikzlibrary{matrix,positioning}
usepackage{caption}
begin{document}
section*{sec 1}
lipsum[1]
begin{tikzpicture}[inner sep=0pt, outer sep=0pt, overlay, remember picture]
matrix[name=F, matrix of nodes, row sep=1ex, column sep={2em}, nodes={text width=.45linewidth, anchor=center, align=center}] at (current page.center) {%
includegraphics[width=linewidth]{example-image-a} & includegraphics[width=linewidth]{example-image-b}
Subcaption a & Subcaption b
includegraphics[width=linewidth]{example-image-c} & includegraphics[width=linewidth]{example-image}
Subcaption c & Subcaption d
};
node [below =belowcaptionskip of F, text width=linewidth] {captionof{figure}{Caption}label{fig}};
end{tikzpicture}
end{document}
Answered by NBur on February 21, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP