2

Context

Based on this answer, I can have 2 figures side by side with adjusted width, same height for sub-figures.

enter image description here

The same approach works for multiple graphs to get something like

enter image description here

I created \newcommand to include 2, 3, 4 graphs side by side. However, I could certainly benefit from automation of this task with keys.

My question

How can I adjust the \width of each raster (same height) so they can fit harmoniously on the \textwidth ?

How can I use tcolorbox raster for this task ?

enter image description here

So far, here is where I stand

enter image description here

turning to

enter image description here

MWE

\documentclass[twoside,a4paper]{book}
\usepackage{caption}
\usepackage[
    showframe, 
    top = 1.8cm, 
    bottom = 2cm, 
    outer = 7cm, 
    inner = 2cm, 
    heightrounded, 
    marginparwidth = 5.0cm, 
    marginparsep = 0.5cm
]{geometry}

\usepackage[most]{tcolorbox} \usetikzlibrary{shadows,patterns} % preamble \tcbuselibrary{raster}

\usepackage{lipsum} \usepackage{tabularray}

\def\fullPage{\dimexpr \marginparwidth+\marginparsep+\textwidth\relax}

\newcommand{\myGraphiX}[2][2]{ \begin{tcbraster}[ % raster width = \fullPage, % raster width = \textwidth, raster columns = #1, % raster force size = false, % raster equal height=rows, size = fbox, colframe = blue!50, colback = white, fonttitle = \bfseries, center title, drop fuzzy shadow, ]

\captionsetup{labelfont = {color = blue,bf,sf}}

\tcbincludegraphics[title = 1st image]{example-image-golden}
\tcbincludegraphics[title = 2nd image]{example-grid-100x100pt}
\tcbincludegraphics[title = 3rd prime]{example-grid-100x100pt}
\tcbincludegraphics[title = 4th matu]{example-image-duck}
\tcbincludegraphics[title = 5th matu]{example-image-a}
\tcbincludegraphics[title = 6th matu]{example-image-b}
\tcbincludegraphics[title = 7th matu]{example-grid-100x100pt}
\tcbincludegraphics[title = 8th matu]{example-image-c}

\begin{tcbitemize}[
    raster multicolumn = #1, %Does not seem to work
    halign = left,
    colframe = white,
    colback = white,
]
\tcbitem \captionof{table}{#2}
\end{tcbitemize}

\end{tcbraster}

}

\begin{document}

\chapter{Auto adjustment to figure height}

\myGraphiX[4]{\lipsum[1][1]}

\myGraphiX[8]{\lipsum[1][2]}

\myGraphiX[2]{\lipsum[1][3]}

\end{document}

Next steps

In a future question, I'll ask how to enter a list of figures with their captions to avoid hardcoding. But one step at a time :)

Edit 1

Using raster equal height as described in the anwer leads to

enter image description here

that is not what I am trying to reach.

JeT
  • 3,020
  • try raster equal height – DG' Mar 01 '22 at 09:20
  • @DG' thank you but. using
    %raster width = \fullPage,
    %raster width = \textwidth,
    raster columns = #1,
    %raster force size = false,
    %raster equal height=rows,
    raster equal height,
    size = fbox,
    colframe = blue!50,
    colback = white,
    fonttitle = \bfseries,
    center title,
    drop fuzzy shadow,
    ]``` 
    leads to the output in Edit 1
    
    – JeT Mar 01 '22 at 09:27
  • 1
    tcbraster divides linewidth in several equal width columns. If you want/need different width columns, you have to adjust them by hand. – Ignasi Mar 01 '22 at 19:40
  • @Ignasi Thank you for your extremely useful comment. As we say in French "it puts the church in the middle of the village" :) – JeT Mar 01 '22 at 20:14

1 Answers1

1

Using raster equal height I get this output:

enter image description here

\documentclass[twoside,a4paper]{book}
\usepackage{caption}
\usepackage[
    showframe, 
    top = 1.8cm, 
    bottom = 2cm, 
    outer = 7cm, 
    inner = 2cm, 
    heightrounded, 
    marginparwidth = 5.0cm, 
    marginparsep = 0.5cm
]{geometry}

\usepackage[most]{tcolorbox} \usetikzlibrary{shadows,patterns} % preamble \tcbuselibrary{raster}

\usepackage{lipsum} \usepackage{tabularray}

\def\fullPage{\dimexpr \marginparwidth+\marginparsep+\textwidth\relax}

\newcommand{\myGraphiX}[2][2]{ \begin{tcbraster}[ % raster width = \fullPage, % raster width = \textwidth, raster columns = #1, % raster force size = false, % raster equal height=rows, size = fbox, colframe = blue!50, colback = white, fonttitle = \bfseries, center title, drop fuzzy shadow, raster equal height, % <-- HERE ]

\captionsetup{labelfont = {color = blue,bf,sf}}

\tcbincludegraphics[title = 1st image]{example-image-golden}
\tcbincludegraphics[title = 2nd image]{example-grid-100x100pt}
\tcbincludegraphics[title = 3rd prime]{example-grid-100x100pt}
\tcbincludegraphics[title = 4th matu]{example-image-duck}
\tcbincludegraphics[title = 5th matu]{example-image-a}
\tcbincludegraphics[title = 6th matu]{example-image-b}
\tcbincludegraphics[title = 7th matu]{example-grid-100x100pt}
\tcbincludegraphics[title = 8th matu]{example-image-c}

\begin{tcbitemize}[
    raster multicolumn = #1, %Does not seem to work
    halign = left,
    colframe = white,
    colback = white,
]
\tcbitem \captionof{table}{#2}
\end{tcbitemize}

\end{tcbraster}

}

\begin{document}

\chapter{Auto adjustment to figure height}

\myGraphiX[4]{\lipsum[1][1]}

\myGraphiX[8]{\lipsum[1][2]}

\myGraphiX[2]{\lipsum[1][3]}

\end{document}

DG'
  • 21,727
  • Sorry, I don't get it. The raster is fixed and the boxes are the same height. What do you want to change? – DG' Mar 01 '22 at 09:38
  • Same height yes, but the width is adjusted as you can see on the 3 graphs below "The same approach works for multiple graphs to get something like" in my question. I'd like to know if I can mimic that with rasters. – JeT Mar 01 '22 at 09:40
  • So you don't want a raster or grid after all? – DG' Mar 01 '22 at 09:46
  • I do actually. I updated the second image on my question to reflect that. – JeT Mar 01 '22 at 09:56
  • As far as I can see, you have to stick to columns. Maybe someone else finds a solution that allows flexible widths – DG' Mar 01 '22 at 10:08
  • Thank you for your investigation :) – JeT Mar 01 '22 at 10:09