4

I'm trying to put 4 figures with unequal heights in a matrix. My code which you can compile here is:

\documentclass[journal=aamick]{achemso}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}
\title{hi}
\begin{document}
\maketitle
\newlength{\w}
\setlength{\w}{.9\paperwidth}

\noindent \begin{tikzpicture}[align=center]

\matrix[column sep=.0\w,row sep=.0\w,%
every node/.style={draw,node distance=0 and 0,outer sep=0},xshift=-.048\w]{
\node [label=above:(a)] (a)  {\includegraphics[width=.14\w]{figs/16_4.jpeg}}; & 
\node [label=right:(d)] (d)  {\includegraphics[width=.14\w]{figs/16_10.jpeg}};\\
\node [label=below:(b)] (b)  {\includegraphics[width=.14\w]{figs/8_4.jpeg}}; &
\node [label=right:(c)] (c)  {\includegraphics[width=.14\w]{figs/8_10.pdf}};\\};

\end{tikzpicture}%

\end{document}

What I'm getting is:

which has a gap (the red arrow) between the left boxes. What I want is sth like:

How can I do this?

  • You can also use a tabular and \raisebox. – John Kormylo Dec 28 '19 at 17:14
3

You only need to set the anchors appropriately, i.e. add

row 1/.style={anchor=south},row 2/.style={anchor=north}

to the options of the matrix.

\documentclass[journal=aamick]{achemso}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}
\title{hi}
\begin{document}
\maketitle
\newlength{\w}
\setlength{\w}{.9\paperwidth}

\noindent \begin{tikzpicture}[align=center]
\matrix[column sep=.0\w,row sep=.0\w,%
every node/.style={draw,outer sep=0},
row 1/.style={anchor=south},row 2/.style={anchor=north}]{
\node [label=above:(a)] (a)  {\includegraphics[width=.14\w]{example-image-duck}}; & 
\node [label=right:(d)] (d)  {\includegraphics[width=.14\w,height=.14\w]{example-image-duck}};\\
\node [label=below:(b)] (b)  {\includegraphics[width=.14\w]{example-image-duck}}; &
\node [label=right:(c)] (c)  {\includegraphics[width=.14\w,height=.14\w]{example-image-duck}};\\};

\end{tikzpicture}%

\end{document}

enter image description here

I do not have your graphics files, so I use some standard files, but with different effective heights to simulate your problem.

ADDENDUM: You can save a few key strokes by using

\setkeys{Gin}{width=.14\w}

since then all the widths of included graphics in this group will have this width. Also nodes is an abbreviation for every node/.append style, and node distance=0 and 0, does not have any effect, nor does ,xshift=-.048\w as long the tikzpicture consists of only this matrix.

\documentclass[journal=aamick]{achemso}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}
\title{hi}
\begin{document}
\maketitle
\newlength{\w}
\setlength{\w}{.9\paperwidth}

\noindent \begin{tikzpicture}[align=center]
\setkeys{Gin}{width=.14\w}
\matrix[column sep=.0\w,row sep=.0\w,%
nodes={draw,outer sep=0},
row 1/.style={anchor=south},row 2/.style={anchor=north}]{
\node [label=above:(a)] (a)  {\includegraphics{example-image-duck}}; & 
\node [label=right:(d)] (d)  {\includegraphics[height=.14\w]{example-image-duck}};\\
\node [label=below:(b)] (b)  {\includegraphics{example-image-duck}}; &
\node [label=right:(c)] (c)  {\includegraphics[height=.14\w]{example-image-duck}};\\};

\end{tikzpicture}%
\end{document}
  • they provides their graphics in the link to overleaf, overleaf.com/read/kxnxhdmxmrtd – Alex Recuenco Dec 28 '19 at 0:24
  • 3
    @AlexRecuenco Thanks! But first of all I do not have an overleaf account, then the link may disappear and finally the answer is meant to work for everyone without the of downloading the graphics. The answer will work for the OP, too, all they need to do is to add row 1/.style={anchor=south},row 2/.style={anchor=north} to the options of the matrix. – Schrödinger's cat Dec 28 '19 at 0:26
  • 1
    that is a great point! – Alex Recuenco Dec 28 '19 at 0:27
  • 1
    @AlexRecuenco. Yes, what I mean is, if there is a way to write that once somewhere and have it applied to all the \includefigures in the \matrix. – Ali Dec 28 '19 at 0:30
  • 2
    @AlexRecuenco Yes. Add \setkeys{Gin}{width=.14\w}. If you add it within the tikzpicture, only the graphics inside the picture will be affected. – Schrödinger's cat Dec 28 '19 at 0:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.