# TikZposter: How to center a tikzfigure within a block

I've noticed that all my tikzfigures (as defined in the tikzposter class) containing \includegraphics statements are off center. As seen in the second innerblock below (excuse the picture, graphicx with the demo option doesn't work under tikzposter), the picture is automatically centered vertically within the block (note the larger space at the top). This happens regardless of the blockstyles that I use. Does anybody know how to properly center it vertically? (redefining tikzfigure to center it's contents vertically does something, but still looks weird)

Moreover, in my actual project, I use a multicols environment with two columns containing figures of different sizes (see the third innerblock). The larger picture is slightly horizontally off center (this is more noticable in my actual project). Additionally, the smaller picture always seems to be placed at the top, instead of the center. I tried various multicol related options to fix this, but none of them see to work. I am not sure if my multicols problem is related to my former problem, but hopefully it is.

MWE:

    \documentclass[25pt, a0paper, portrait, margin=0pt, innermargin=5pt, colspace=45pt, blockverticalspace=5pt]{tikzposter}

% dummy text generation
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage{xpatch}
\usepackage{todonotes}
\usepackage{multicol}

% remove space that empty innerblock title leaves behind
% see https://tex.stackexchange.com/questions/447378/tikzposter-leaves-a-gap-in-empty-innerblock-title
\makeatletter
\xpatchcmd{\innerblock}{\node[minimum width=\TP@innerblocktitlewidth, minimum height=\TP@innerblocktitleheight, anchor=center] (innerblocktitle)}{\node[inner sep=0pt, minimum width=\TP@innerblocktitlewidth, minimum height=\TP@innerblocktitleheight, anchor=center] (innerblocktitle)}{}{}
\makeatother

\defineinnerblockstyle{myinner}{
titlewidthscale=1, bodywidthscale=1, titlecenter,
titleoffsetx=0pt, titleoffsety=0pt, bodyoffsetx=0pt, bodyoffsety=0pt,
bodyverticalshift=0pt, roundedcorners=0, linewidth=0.0cm,
titleinnersep=0pt, bodyinnersep=20pt
}{
\filldraw[innerblockbodybgcolor]
(innerblockbody.south west) rectangle (innerblockbody.north east);
\draw [line width=0.5cm,blue] (innerblockbody.south) -- (innerblockbody.north);
}

\usetheme{Simple}
\usebackgroundstyle{Empty}

\useblockstyle{Basic}
\useinnerblockstyle{myinner}

\title{Test Test Test}
\author{Myself}
\date{\today}
\institute{University of Foobar}

\begin{document}

\maketitle

\setlength\columnseprule{0.32cm}
\colorlet{blockbodybgcolor}{blue}
\block{Blocktiltle}{
\colorlet{innerblockbodybgcolor}{white}
\innerblock{}{\lipsum[1]}
\colorlet{innerblockbodybgcolor}{gray}
\innerblock{}{
\centering
\begin{minipage}{0.9\linewidth}
\centering
\begin{tikzfigure}
\includegraphics[width=1.0\linewidth]{example-image-duck}
\end{tikzfigure}
\end{minipage}\hfill}
\colorlet{innerblockbodybgcolor}{red}
\innerblock{}{
\centering

\begin{minipage}{0.49\linewidth}
\centering
\begin{tikzfigure}
\includegraphics[width=0.49\textwidth]{example-image-duck}
\end{tikzfigure}
\end{minipage}\hfill
\begin{minipage}{0.49\linewidth}
\begin{tikzfigure}
\includegraphics[width=0.495\textwidth]{example-image-duck}
\includegraphics[width=0.495\textwidth]{example-image-duck}
\end{tikzfigure}
\end{minipage}
}
}

\end{document}


Welcome to TeX.SE! According to this nice answer, the most efficient way may be the very old method of using minipages.

\documentclass[25pt, a0paper, portrait, margin=0pt, innermargin=40pt, colspace=45pt, blockverticalspace=45pt]{tikzposter}

% dummy text generation
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage{xpatch}
\usepackage{todonotes}
\usepackage{multicol}

% remove space that empty innerblock title leaves behind
% see https://tex.stackexchange.com/questions/447378/tikzposter-leaves-a-gap-in-empty-innerblock-title
\makeatletter
\xpatchcmd{\innerblock}{\node[minimum width=\TP@innerblocktitlewidth, minimum height=\TP@innerblocktitleheight, anchor=center] (innerblocktitle)}{\node[inner sep=0pt, minimum width=\TP@innerblocktitlewidth, minimum height=\TP@innerblocktitleheight, anchor=center] (innerblocktitle)}{}{}
\makeatother

\defineinnerblockstyle{myinner}{
titlewidthscale=1, bodywidthscale=1, titlecenter,
titleoffsetx=0pt, titleoffsety=0pt, bodyoffsetx=0pt, bodyoffsety=0pt,
bodyverticalshift=0pt, roundedcorners=0, linewidth=0.0cm,
titleinnersep=0pt, bodyinnersep=20pt
}{
\filldraw[innerblockbodybgcolor]
(innerblockbody.south west) rectangle (innerblockbody.north east);
}

\usetheme{Simple}
\usebackgroundstyle{Empty}

\useblockstyle{Basic}
\useinnerblockstyle{myinner}

\title{Test Test Test}
\author{Myself}
\date{\today}
\institute{University of Foobar}

\begin{document}

\maketitle

\setlength\columnseprule{0.32cm}
\colorlet{blockbodybgcolor}{blue}
\block{Blocktiltle}{
\colorlet{innerblockbodybgcolor}{white}
\innerblock{}{\lipsum[1]}
\colorlet{innerblockbodybgcolor}{gray}
\innerblock{}{
\begin{tikzfigure}
\includegraphics[width=0.22\linewidth]{example-image-duck}
\end{tikzfigure}}
\colorlet{innerblockbodybgcolor}{red}
\innerblock{}{
\centering% https://tex.stackexchange.com/a/263807/121799
\begin{minipage}[c]{0.45\linewidth}
\begin{tikzfigure}[Caption of figure1]
\centering
\includegraphics[width=0.21\linewidth]{example-image-a}
\end{tikzfigure}%
\end{minipage}\hfill
\begin{minipage}[c]{0.45\linewidth}
\begin{tikzfigure}[Caption of figure2]
\centering
\includegraphics[width=0.45\linewidth]{example-image-b}
\end{tikzfigure}%
\end{minipage}%
}
}
\end{document}


• Thanks for your answer! Using minipages instead of multicols seems to result in more predictable behavior. However, a lot my contents (esp. in my final project) are still of center). For starters, none of the figures are centered vertically (as seen in e.g. your second innerblock, note the space on the top). Maybe I'm a bit at fault for asking solutions to two different problems tho (ways centering stuff in minipages might be different elsewhere) – rien333 Aug 25 '18 at 10:53
• Moreover, placing multiple graphics side by side within a minipage doesn't seem to center them horizontally, at least relative to a tikz seperator line I draw through the middle of my figure. This might be, among other things, related to the figure not being aware of the tikz seperator line, but I can't manually adjust my figures for this as they don't seem to respect e.g. \hspace shifts. I've updated my MWE to reflect this problem, I hope this doesn't change my original question too much. – rien333 Aug 25 '18 at 10:57
• @rien There is a long literature about minipage relative vertical alignment. Basically, you can add options like [t], [b], [c] and so on, see e.g. here and here. I thought the pics were centered but if they are not I will be happy to delete the post. As for the horizontal centering, just add \centering after \begin{tikzpigure}. – user121799 Aug 25 '18 at 10:59
• The separator line I'm speaking of is not just a visual guide btw, but something I actually want to use in my poster. (see my included image which shows an off center image in the bottom right) – rien333 Aug 25 '18 at 11:00
• It seems that if I use \hspace* and \vspace* within the tikzfigure environment that I can slightly adjust the figures as to center them. Bit of an ugly workaround though, but for now I don't really care. – rien333 Aug 25 '18 at 11:13

Not an answer, but putting a grid in the marmot answer seem that the example-image-a is a little on the left, and the example-image-b is a little on the right.

\documentclass[25pt, a0paper, portrait, margin=0pt, innermargin=40pt, colspace=45pt, blockverticalspace=45pt]{tikzposter}

% dummy text generation
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage{xpatch}
\usepackage{todonotes}
\usepackage{multicol}

% remove space that empty innerblock title leaves behind
% see https://tex.stackexchange.com/questions/447378/tikzposter-leaves-a-gap-in-empty-innerblock-title
\makeatletter
\xpatchcmd{\innerblock}{\node[minimum width=\TP@innerblocktitlewidth, minimum height=\TP@innerblocktitleheight, anchor=center] (innerblocktitle)}{\node[inner sep=0pt, minimum width=\TP@innerblocktitlewidth, minimum height=\TP@innerblocktitleheight, anchor=center] (innerblocktitle)}{}{}
\makeatother

\defineinnerblockstyle{myinner}{
titlewidthscale=1, bodywidthscale=1, titlecenter,
titleoffsetx=0pt, titleoffsety=0pt, bodyoffsetx=0pt, bodyoffsety=0pt,
bodyverticalshift=0pt, roundedcorners=0, linewidth=0.0cm,
titleinnersep=0pt, bodyinnersep=20pt
}{
\filldraw[innerblockbodybgcolor]
(innerblockbody.south west) rectangle (innerblockbody.north east);
}
%%very usefull test grid%%
\newcommand{\myGrid}{%
\begin{tikzpicture}[
overlay,
remember picture,
shift={(current page.north west)}
]
\draw[very thin, blue!10, xstep=\paperwidth/50, ystep=\paperheight/50]
(current page.south west) grid (current page.north east);
\draw[very thin, green!50!black, xstep=\paperwidth/10, ystep=\paperheight/5]
(current page.south west) grid (current page.north east);
\end{tikzpicture}%
}
%%%%%%%

\usetheme{Simple}
\usebackgroundstyle{Empty}

\useblockstyle{Basic}
\useinnerblockstyle{myinner}

\title{Test Test Test}
\author{Myself}
\date{\today}
\institute{University of Foobar}

\begin{document}

\maketitle

\setlength\columnseprule{0.32cm}
\colorlet{blockbodybgcolor}{blue}
\block{Blocktiltle}{
\colorlet{innerblockbodybgcolor}{white}
\innerblock{}{\lipsum[1]}
\colorlet{innerblockbodybgcolor}{gray}
\innerblock{}{
\begin{tikzfigure}
\includegraphics[width=0.22\linewidth]{example-image-c}
\end{tikzfigure}}
\colorlet{innerblockbodybgcolor}{red}
\innerblock{}{
\centering% https://tex.stackexchange.com/a/263807/121799
\begin{minipage}[c]{0.45\linewidth}
\begin{tikzfigure}[Caption of figure1]
\centering
\includegraphics[width=0.21\linewidth]{example-image-a}
\end{tikzfigure}%
\end{minipage}\hfill
\begin{minipage}[c]{0.45\linewidth}
\begin{tikzfigure}[Caption of figure2]
\centering
\includegraphics[width=0.45\linewidth]{example-image-b}
\end{tikzfigure}%
\end{minipage}%
\myGrid%
}
}
\end{document}


• Neat, this will at least help me do manual correction for some tikz weirdness. – rien333 Aug 31 '18 at 10:09
• @rien333 I've find that replacing \begin{minipage}[c]{0.45\linewidth} with \begin{minipage}[c]{0.45\paperwidth} for the example-image-a and example-image-b give the centering with respect to the block, but not with respect to the page. – vi pa Aug 31 '18 at 10:53
• @rien333 By trial and errors I've find that the using \begin{minipage}[c]{0.45\paperwidth-50pt} give the correct centering with respect to the page, but I don't understand why. – vi pa Aug 31 '18 at 11:21