Graphics, Figures & TablesImage alignment in minipage and common colorbar

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
User avatar
Phtagen
Posts: 4
Joined: Mon Aug 30, 2021 3:27 pm

Image alignment in minipage and common colorbar

Post by Phtagen »

Hello evereyone,

I have some trouble with the image alignment in a minipage environment. I have 4 images and I need to align them in 2 coloumns. Left col 1 big image, right col 3 smaller images. I want the top of the right images to be algigned with the top edge of the left image and I want the right bottom image to be aligned with the bottom edge of the left bigger image. So, far the prinicipal alignment works, but the images are not aligned at the bottom.

Further I want to have a shared colorbar for the 3 smaller images. I prepared an example (in excel) and attached it.
The images have a custom lookup table, therefore I think I have to add the colorbar as a 5th image. If this is the case, I think I will have to use tikz in order to get axes tiks and labels on the colorbar.

I am not sure, wether minipage is the optimal solution here. If anyone has a better approach it's welcome.


Code: Select all

\documentclass{article}

\usepackage{mwe}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage[format=hang,justification=raggedright]{caption}
\usepackage{multicol}
\usepackage[export]{adjustbox}
\usepackage{float}
\usepackage{pgfplotstable}
\usepackage{subfiles}

% Inserts a scale bar into an image
% Optional argument 1: the colour of the bar and text
% Argument 2: an \includegraphics command
% Argument 3: the real world width of the image
% Argument 4: the length of the scale bar in pixels
% Argument 5: the length of the scale bar in mm
% Argument 6: the unit
% Usage: \scalebar{\includegraphics[width=\linewidth]{image.png}}{1186}{9.887}{15}{mm} 
% src: https://gist.github.com/rbnvrw/00312251b756f6b48084#file-latexscalebars-md
\newcommand{\scalebar}[6][white]{
 \begin{tikzpicture}
  \node[anchor=south west,inner sep=0] (image) { #2 };
  \begin{scope}[x={(image.south east)},y={(image.north west)}]
   \draw [#1, line width=0.1em] (0.04,1.2em) -- node[below,inner sep=0.1em, font=\scriptsize] {\SI{#5}{#6}} (#4/#3+0.04,1.2em);
  \end{scope}
 \end{tikzpicture}
}

\begin{document}

\begin{figure}[htbp!]
\centering
    \begin{minipage}[t]{.45\textwidth}
        \vspace{0pt}
        \subfloat[][]{\scalebar{\includegraphics[width=.9\textwidth]{example-image-1x1}}{200}{0}{}{}\label{val13_axial}}\par
        \hfill
    \end{minipage}\hfill
    \begin{minipage}[t]{.45\textwidth}
        \vspace{0pt}
        \subfloat[][]{\scalebar{\includegraphics[width=.4\textwidth]{example-image-1x1}}{200}{0}{}{}\label{val13_top}}
        \vfill
        \subfloat[][]{\scalebar{\includegraphics[width=.4\textwidth]{example-image-1x1}}{200}{0}{}{}\label{val13_mid}}
        \vfill
        \subfloat[][]{\scalebar{\includegraphics[width=.4\textwidth]{example-image-1x1}}{200}{0}{}{}\label{val13_bottom}}
        \vspace{0pt}
        
    \end{minipage}%
    
\caption{Write caption here!!! }
\label{fig:val13_quanti}
\end{figure}

\end{document}
And this is, how it should finally look:
Screenshot (1)-1.jpg
Screenshot (1)-1.jpg (124.72 KiB) Viewed 10831 times
Greetings Phtagen

Edit:
I am sorry, but the output produces an error, because "\rule" is not recognized. I am not quiet sure how to handle the included graphics prpoerly online??? The principal code works for me without errors, but
1) the images are not properly aligned
2) I don't know how to get the desired colorbar on the right.
Last edited by Phtagen on Tue Aug 31, 2021 2:00 pm, edited 13 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Image alginment in minipage and common colorbar

Post by rais »

Well,
Phtagen wrote:

Code: Select all

        \subfloat[][]{\scalebar{\includegraphics[width=.9\textwidth]{\rule}}{1700}{322.6}{2}{mm}
you seem to have replaced the name of the image with `\rule'.
Since \rule expects at least two parameters (width and height), it would `eat' the two following closing braces...
Anyway, I guess there's no image file found on your system that matches the expansion of `\rule'.
If you want to use \rule to represent your image(s), you'd have to skip the \includegraphics command and provide \rule with width and height.
If that works within your \scalebar, I haven't checked.

KR
Rainer
User avatar
Phtagen
Posts: 4
Joined: Mon Aug 30, 2021 3:27 pm

Image alginment in minipage and common colorbar

Post by Phtagen »

Hi Rainer,

I know. I have written, that the compilation stumbles at \rule. I just used \rule as a placeholder (I read this here https://www.minimalbeispiel.de/ and thought it was good practice in order to provide a mwe).

Anyway, I don't know how to incorporate my images here, online. That's why I used \rule.

\scalebar is a macro I found in another forum, it works fine (with images, with \rule probably not).

Greetings

Edit: I could replace \includegraphics as you proposed, but it was more important to me, to show what general structure I'm using. Especially with regard to \scalebar, since this macro has an influence on the alignment of the images.
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Image alginment in minipage and common colorbar

Post by rais »

Hi Phtagen,
well, if you think you need pictures and cannot upload the pictures in question---in some cases it's not even allowed because of copyright restrictions, company rules, who-knows-what-else---perhaps you can use some of the images provided with the mwe package. Those would be images anyone has (well, as long as mwe is installed on her/his system).

KR
Rainer
User avatar
Phtagen
Posts: 4
Joined: Mon Aug 30, 2021 3:27 pm

Image alginment in minipage and common colorbar

Post by Phtagen »

Hi Rainer,

thanks for the hint with the mwe-package. Nevertheless, I didn't manage to make it work including my \scalebar macro. Anyway, this is more or less of secondary interest, the focus is on the arangement of the images as described in my first post. I revised my code, so here is the working mwe:

Code: Select all

\documentclass{article}

\usepackage{mwe}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage[format=hang,justification=raggedright]{caption}
\usepackage{multicol}
\usepackage[export]{adjustbox}
\usepackage{float}
\usepackage{pgfplotstable}
\usepackage{subfiles}

\begin{document}

\begin{figure}[htbp!]
\centering
    \begin{minipage}[t]{.7\textwidth}
        \vspace{0pt}
        \subfloat[][]{\includegraphics[width=.95\textwidth]{example-image-1x1}\label{val13_axial}}\par
        \hfill
    \end{minipage}\hfill
    \begin{minipage}[t]{.25\textwidth}
        \vspace{0pt}
        \subfloat[][]{\includegraphics[width=.65\textwidth]{example-image-1x1}\label{val13_top}}
        \vfill
        \subfloat[][]{\includegraphics[width=.65\textwidth]{example-image-1x1}\label{val13_mid}}
        \vfill
        \subfloat[][]{\includegraphics[width=.65\textwidth]{example-image-1x1}\label{val13_bottom}}
        \vspace{0pt}
        
    \end{minipage}%
    
\caption{Write caption here!!! }
\label{fig:val13_quanti}
\end{figure}

\end{document}
As you can see, the images are not aligned at the bottom edge. I thought \vfill could do the job but it doesn't.

The second thing is the calibration bar on the right side (not yet included). I don't have any clue how to include this, properly aligned with the other images and without having a subcaption (see my first post).

Greetings
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Image alginment in minipage and common colorbar

Post by Ijon Tichy »

\vspace{\fill} or \vfill can only fill, if the box has a defined height. A minipage without the optional height parameter does have its natural height, so there is nothing to fill.

Code: Select all

\documentclass{article}

\usepackage{mwe}
\usepackage[utf8]{inputenc}% Not needed since LaTeX 2018/04/01
\usepackage{graphicx}
\usepackage{subfig}
\usepackage[format=hang,justification=raggedright]{caption}
\usepackage{multicol}% Not used in the example.
\usepackage[export]{adjustbox}% Not used in the example, but could be used instead of \raisebox to move the TikZ picture down
\usepackage{float}% Not used in the example
\usepackage{pgfplotstable}% In the example only used to load package tikz.
\usepackage{subfiles}% Not used in the example

\begin{document}

\begin{figure}[htbp!]% The options (i.e. option !) should be used only if needed in some cases, but not generally.
\centering
    \begin{minipage}[t][.7\textwidth]{.7\textwidth}
        \vspace{0pt}
        \subfloat[][]{\includegraphics[width=.95\textwidth]{example-image-1x1}\label{val13_axial}}\par
        \hfill
    \end{minipage}\hfill
    \begin{minipage}[t][.7\textwidth]{.25\textwidth}
        \vspace{0pt}
        \subfloat[][]{\includegraphics[width=.65\textwidth]{example-image-1x1}\label{val13_top}}
        \vfill
        \subfloat[][]{\includegraphics[width=.65\textwidth]{example-image-1x1}\label{val13_mid}}
        \vfill
        \subfloat[][]{\includegraphics[width=.65\textwidth]{example-image-1x1}\label{val13_bottom}}
    \end{minipage}%
      \raisebox{-\totalheight}{\tikz \shade[bottom color=brown,top color=yellow] (0,0) rectangle (0.5,0.665\textwidth);}
\caption{Write caption here!!! }
\label{fig:val13_quanti}
\end{figure}

\end{document}
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
User avatar
Phtagen
Posts: 4
Joined: Mon Aug 30, 2021 3:27 pm

Image alginment in minipage and common colorbar

Post by Phtagen »

Hi Ijon Tichy,

thank you very much, your approach really helped.

I just changed one thing, regarding the colorbar, since the shading didn't fit:

Code: Select all

\documentclass{article}

\usepackage{mwe}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage[format=hang,justification=raggedright]{caption}
\usepackage{pgfplotstable}

\begin{document}

\begin{figure}[htbp!]
\centering
    \begin{minipage}[t][.65\textwidth]{.65\textwidth}
        \vspace{0pt}
        \subfloat[][]{\includegraphics[width=.95\textwidth]{example-image-1x1}\label{val13_axial}}\par
        \hfill
    \end{minipage}\hfill
    \begin{minipage}[t][.65\textwidth]{.2\textwidth}
        \vspace{0pt}
        \subfloat[][]{\includegraphics[width=.8\textwidth]{example-image-1x1}\label{val13_top}}
        \vfill
        \subfloat[][]{\includegraphics[width=.8\textwidth]{example-image-1x1}\label{val13_mid}}
        \vfill
        \subfloat[][]{\includegraphics[width=.8\textwidth]{example-image-1x1}\label{val13_bottom}}
    \end{minipage}\hfill
    \begin{minipage}[t][.65\textwidth]{.1\textwidth}
        \vspace{0pt}
        \includegraphics[width=0.5cm, height=6.175\textwidth]{example-image-9x16}\hfill
    \end{minipage}
\caption{Write caption here!!! }
\label{fig:val13_quanti}
\end{figure}

\end{document}
So far so good. The only things missing are the label (C [ ]) and the axis ticklabels(0.0 and 1.0), please refer to my first post. I am not very familiar with tikz, but I guess this will be the route to go?!?

Greetings
Post Reply