In the MWE below, which currently results with this output (click for full-res):
... I want to:
- Arrange four images in 2 rows, 2 columns, for which I've used a
\matrix
of\tikz
nodes, - Have them all rotated on the page, including the caption,
- Scale these images, such that they fill out remaining page space (or, fit their respective container nodes) - while keeping aspect ratio, and respecting the
row sep
andcolumn sep
of the\matrix
- Annotate them with, say, tikz
\draw
commands (in principle, I'd add red rectangle borders around the circles on the images, but here they're just centered for the sake of simplicity).
Here are the problems in the current example:
- The
\node
s in the\matrix
do scale according to page height (as they are rotated, with their width) - but the rotated nodes' height spills over the page width - The easiest way for me to obtain the coordinates of the annotating rectangles, is to use
tikzedt
, setting the image width to 10cm; and ultimately using the numbers produced (e.g.\draw[rd] (1.1,1.1) node (f1) {} rectangle (-1.1,-1.1);
) as scaling factors in respect to the final image width (e.g.\draw[rd] (1.1\imw,1.1\imw) node (f1) {} rectangle (-1.1\imw,-1.1\imw);
). The problem is, here I do not know what the final image width is, since the images are supposed to be scaled
Also, in the MWE, also the caption leaks outside the page margin - but that might actually be OK in this case, given how wide the page margins are. So I'd like to know how to achieve this in both cases: both with the caption fitting inside the page boundaries; and with the caption sitting outside page boundaries, and only the matrix of node/images fitting inside.
So, what would be the easiest way, to achieve scaling of images, keeping aspect ratio, into a matrix of nodes that scales to (fits) the page size inside the margins - both with the caption sitting inside, and outside, the page margin boundaries; and obtaining their final sizes, so as to use them for annotation drawings' coordinates?
EDIT: Just figured out that I mixed up the widths and heights for the images in the MWE below; so if in the MWE below all instances of max size={0.5\textwidth}{0.5\textheight}
with max size={0.5\textheight}{0.5\textwidth}
are replaced, I get the much more expected output:
The scale size of the images now seems OK (though note that img1, since it is smaller than the node bounds, doesn't scale up - that is however no problem in this case) - but the positioning, as a whole, is still off in respect to page margin boundaries (and it seems kinda related to the caption); so the rest of the question(s) still stand(s)...
The MWE code:
\documentclass[10pt,twoside,openright]{book}
% to generate images, run the first time with:
% pdflatex -shell-escape test.tex
% (ImageMagick `convert` commands tested in `bash` shell)
\immediate\write18{
convert -size 200x100 gradient:\#4b4-\#bfb -fill gradient:green-yellow -draw 'circle 50,30 50,50' img1.png ;
convert -size 100x200 gradient:\#44b-\#bbf -fill gradient:green-yellow -draw 'circle 70,130 70,150' img2.png ;
convert -size 300x200 gradient:\#b44-\#fbb -fill gradient:blue-yellow -draw 'circle 250,30 250,50' img3.png ;
convert -size 200x300 gradient:\#4bb-\#ffb -fill gradient:blue-yellow -draw 'circle 70,230 70,250' img4.png ;
}
\usepackage{tikz}
\usepackage[export]{adjustbox}
\pagecolor{yellow!10} % \usepackage{xcolor}
\usepackage{lua-visual-debug} % compile with lualatex test.tex, for visual indication of margins
% both of these use adjustbox:
% http://tex.stackexchange.com/questions/32886/how-to-fit-a-large-figure-to-page
% http://tex.stackexchange.com/questions/44427/rotate-picture-with-caption
% note: \draw tikz dimensions: in unit centimeter
\begin{document}
\begin{figure}[p]
\begin{adjustbox}{addcode={\begin{minipage}{\width}}{\caption{%
Here is a caption of the figure which is so long that
it has to be wrapped over multiple lines, but should
not exceed the width (height after the rotation) of the image.
}\end{minipage}},rotate=90,center}
%
%\includegraphics[scale=.6]{test/picture.png}%
%
\begin{tikzpicture}[
ns/.style={inner sep=0pt,outer sep=0pt},
mw/.style={minimum width=0.5\textheight, minimum height=0.5\textwidth},
rd/.style={draw=red,line width=2pt},
]
\matrix[ns,row sep=1mm,column sep=1mm] {
% row 1, col 1:
\node[ns,mw,draw] {%
\includegraphics[max size={0.5\textwidth}{0.5\textheight},keepaspectratio]{img1.png}%
};%
\draw[rd] (1.1,1.1) node (f1) {} rectangle (-1.1,-1.1);%
&% %end column%
% row 1, col 2:
\node[ns,mw,draw] {
\includegraphics[max size={0.5\textwidth}{0.5\textheight},keepaspectratio]{img2.png}%
};%
\draw[rd] (1.1,1.1) node (f2) {} rectangle (-1.1,-1.1);%
\\% %end row%
% row 2, col 1:
\node[ns,mw,draw] {
\includegraphics[max size={0.5\textwidth}{0.5\textheight},keepaspectratio]{img3.png}%
};%
\draw[rd] (1.1,1.1) node (f3) {} rectangle (-1.1,-1.1);%
&% %end column%
% row 2, col 2:
\node[ns,mw,draw] {
\includegraphics[max size={0.5\textwidth}{0.5\textheight},keepaspectratio]{img4.png}%
};%
\draw[rd] (1.1,1.1) node (f4) {} rectangle (-1.1,-1.1);%
\\% %end row%
};
\end{tikzpicture}
%
\end{adjustbox}
\end{figure}
\end{document}
raster
library frontcolorbox
package. tex.stackexchange.com/a/222951/1952, tex.stackexchange.com/a/224531/1952tcolorbox
indeed looks like it might work, except I cannot tell how it would handle rotation and eventual position of the caption, which is also an issue here... Cheers!