Floating minipages and other wizardry

Inspired by a current issue from my friend the LaTeX Noob, I wanted to give a short explanation on how you can combine floats (i.e. figures) and minipages. Why should you care? Well, if you need tikzpicture or images placed besides eachother or beside text. So most people will probably need this at some point πŸ˜‰ A great resource is the WikiBook, as always. If you want the lengthy account – that’s the way to go. For everybody else, an explanation of my own.

Floats and non-floating boxes

What are floats?

Some fundamental explanations first: A figure is a float. A minipage is not a float but a box which sits at its fixed place. These are two fundamentally different things. When you combine them in a bad way, LaTeX might get fed up at this. So when planning your minipaging or floating situation, ask yourself which effects are really important to you and which aren’t.

Do I even need a float?

A float will self-regulate positioning pretty much. If you need this feature, you need a float. But maybe this is a behaviour you explicitly don’t want anyway. Then maybe you don’t even need a float at all. Beginners often get confused and think they need to use figures everywhere but, strictly speaking, you don’t. You can, for example, just \includegraphics without a figure. Then the thing will just not have floating behaviour and you also might want captions and stuff, so an environment might be in order. But this need not be a figure. But if you don’t want all this, be aware that you might not need a figure at all and save yourself some trouble debugging.

I would suggest you probably go for figures anyway if it’s a long document where positioning might change dramatically after you first insert the picture, minipage or whatever. If, however, your result is pretty static and not a pages long document, you might just be better off leaving out the floats completely. Like, for example, in a poster, positioning isn’t really up for LaTeX to decide. You need it placed in a stable, reliable way and the way you want it and you exert lots of ‘control’ over the whole process.

Floats are better if you are dealing with a thing whose behaviour LaTeX is supposed to regulate acccording to its own best judgement. And as we all know, LaTeX’s judgement is pretty awesome. So this is a feature you might very well want to profit from in most cases. Also, you might want a \listoffigures. Or not. So think about that.

A little rant on “LaTeX is not doing what I want”

Beginners often get fed up with this behaviour because “LaTeX is not doing what I want”. This is probably due to the fact that you are using structures you think are supposed to do XYZ while they actually are programmed to do ABC. This is just a ‘misunderstanding’ between LaTeX and the user and can be remedied by additional knowledge about how some things work internally. So a general good bit of advice would be to look up how a structure you are trying to use is programmed to work internally. Most of the time, looking up the official documentation will already suffice. Probably it is supposed to do something completely different than what you thought it was or wanted it to. This is not LaTeX’s fault. It’s the fault of the user who doesn’t bother to look up those basic functionalities, so don’t blame LaTeX. But of course, if you’re still a beginner, this is a normal thing to do or expect. A common false assumption among programming novices. So don’t worry either. Next time you will know what to do.

A computer will do what you wrote down. Not what you meant. Even and especially, if the two are not the same thing πŸ˜‰

The objective: placing things side by side

We will follow up with some examples of figures and minipages. By now, you are already informed what the differences are and can make an intelligent choice πŸ˜‰

Case 1: The figure placed right here

The following is just a figure, but it will be forced to be placed right here (as indicated per the H). Using a small h really only means ‘here if it fits’. Only h! or H actually mean HERE!!!Also, read this great (lenghty) information on floats if you want to know more. Don’t forget to \usepackage{float} if you want to use the H. Edit: Thanks to Karl from LaTeX ref who informed me that h! basically only sometimes accidentally results in “place it HERE”. Use H for reliability.

So depending on your other needs (\listoffigures, etc.), you might as well have not used a floating environment since obviously, you did not intend for the thing to float.


Case 2: Figure beside text with wrapfigure

The same thing like with minipage, basically, can be achieved with a wrapfigure, which you might need at some point too. This will make an image float beside text. On this, read the Overleaf tutorial.

    \begin{tikzpicture}[opacity=0.8, scale=0.5]
    \basesketch \angles
    \filldraw[draw=black, fill=lila, fill opacity=0.3] (A) -- (B) -- (C) -- cycle;
    \filldraw[draw=black, fill=myblue, fill opacity=0.3] (A) -- (C) -- (K2) -- (K1) -- cycle;
    \caption{T\textsubscript{1} und T\textsubscript{2}}

Case 3: lifesaving minipages

First, I’ll explain the basic functionality of minipages and then issue some personal tips on how to use them πŸ˜‰


As you might have noticed, you have options when configuring your minipage: \begin{minipage}[adjusting]{width of the minipage} are the available ones. Meaning minipage has a specified alignment and a predetermined width. Although, you can use relative widths, of course. So it can be {3cm} or {0.3\textwidth} according to your needs. Notice however, that you cannot use 100% textwidth in total while still having everything aligned. Take off 0.03 in total to be sure. So all your minipages which are placed side by side cannot take up a total of 100% of the textwidth.

c = center, t = top and b = bottom are the alignment choices. c is default, I mostly use t. It can be a bit difficult to grasp what they actually do. They specify at which line the content gets aligned. So t means, the alignment will be oriented on the topmost, so the highest line.

Also, we can add more options [t][3cm][b] which additionally says that we have a fixed height of 3cm and the content will be aligned at the bottom. The (multiple) minipages themselves will be aligned at their tops.

Alignment of multiple minipages

Also, if you want multiple minipages aligned at their sides and not below eachother, you can’t have blank lines between them. Inside the minipage environments is no problem, but not following the first one before the second one, for example. See also Sasha Frank’s page and this.

When you check StackOverflow “How to use a figure inside a minipage” – the short answer is: You don’t!


If you want to make two floats happily float, but in a row beside eachother, you can use the floatrow package, as detailed in this StackOverflow post.

Do I need a float now or what? Combining figure and minipage

If you don’t insist on having a float, people would probably go for minipage to make things sit aligned besides eachother and connected.

It is also not necessary to place your \includegraphics inside a figure, though a lot of beginners think so. Just put your images directly in a minipage if you don’t need floating behaviour. If you do – add a float. But not inside the minipage, this will cause an error. If you are confused about this, imagine a rubber duck floating in your bathtub. You cannot place it into a box because then it will sink. You can, however, make it carry a box on its back. So, this is basically the same thing with floats an minipages πŸ˜‰

You cannot have a figure (=float) inside a minipage (non-floating box) since it will make the rubber duck sink. Don’t sink your rubber duck! Read up on it hereΒ (just to warn you, they don’t use rubber ducks for explanation, so don’t be disappointed).

And, by the way, it also doesn’t make sense to have float inside a fixed box. Float means, LaTeX decides where exactly to place elements. But if you put a fixed box, you have already made that decision. Nothing left for LaTeX to decide. Meaning LaTeX will go and sulk at you. If you need LaTeX to calculate where to put things and it is possible your document will change a lot, it’s better to use floats. If you want everything exactly where you want it, float will make you go crazy. You can put tikzpicture inside minipages. It’s confusing, I know.

And remember: If you don’t want the minipages to become “disconnected”, which is usually the case, make sure you don’t put an empty line after one of them. They should be “connected” in the code if you want them connected in the output.

Another example (snippet) from my personal CV template to visualize language skills. As you can see, you might be able to achieve what you want using a tabular as well.


This is how the code looks like:

%------------------- pictogram Fraction: pictoFraction
\pgfmathparse{#3 - 1}\foreach \n in {0,...,\pgfma<span 				data-mce-type="bookmark" 				id="mce_SELREST_start" 				data-mce-style="overflow:hidden;line-height:0" 				style="overflow:hidden;line-height:0" 			></span>thresult}{\icon{#1}{#2}{#6}}%
\pgfmathparse{#5 - 1}\foreach \n in {0,...,\pgfmathresult}{\icon{#1}{#4}{#6}}%

\begin{tabular}{l | ll}
\textbf{German} & C2 & {\phantom{x}\footnotesize mother tongue} \\
\textbf{English} & C2 & \pictofraction{\faCircle}{blue}{3}{blue}{1}{\tiny}\\
   \textbf{Latin}  & C2 & \pictofraction{\faCircle}{blue}{3}{blue}{1}{\tiny}\\
   \textbf{French} & C2 & \pictofraction{\faCircle}{blue}{3}{blue}{1}{\tiny}\\
   \textbf{Ancient Greek} & B2 & \pictofraction{\faCircle}{blue}{3}{grey!30}{1}{\tiny}\\


There also is the subcaption package (subfigure or subfig are deprecated). Here, you can use sub-floats inside a single float. Here is an example of how to use it.

You can also put minipages inside a float, to make the whole thing float again. And that’s about it πŸ˜‰

And just for your reference, I included the actual TikZ at the bottom of the post. Just in case you wanted it or whatever πŸ˜‰

I really love minipages. They are my go-to thing for anything and everything. Sometimes even when there probably would be another (better) option available. Minipages rock! And so do you!


the LaTeX Ninja

The TikZ

\node[](Kreismittelpunkt) at (0,0) {};
\node[](K1) at (0,6) {};
\node[](K2) at (4,5) {};

\draw[] (Kreismittelpunkt) -- ++(0:5cm) node[](C){} -- ++(0:5cm) node[](K2){};
\draw[] (Kreismittelpunkt) -- ++(30:4cm)  node[](A){}  --  ++(30:2cm)  node[](B){}  -- ++(30:4cm) node[](K1){};
\draw[] (K2) -- (K1);
\draw[fill=myblue] (K2) circle (2.5pt) node[below=0.5em]{K\textsubscript{2}};
\draw[fill=myblue] (K1) circle (2.5pt) node[above=0.5em]{K\textsubscript{1}};

\draw[fill=myblue] (A) circle (2.5pt) node[above=0.5em]{A};
\draw[fill=myblue] (B) circle (2.5pt) node[above=0.5em]{B};
\draw[fill=myblue] (C) circle (2.5pt) node[below=0.5em]{C};
\draw[] (A) -- (C);
\draw[] (C) -- (B);
\draw[] (B) -- (K2);

% coordinates
\coordinate (K2) at (K2);
\coordinate (K1) at (K1);
\coordinate (A) at (A);
\coordinate (B) at (B);
\coordinate (C) at (C);

\draw[fill=myblue] (Kreismittelpunkt) circle (2.5pt) node[below=0.5em]{K};

% Alternative zu Arc zwischen zwei Punkten
\draw[-,draw=black!70] (K2) to[bend right=12] (K1);

\pic[draw=black!70,text=black!70, -,"$\alpha$"] {angle =A--C--Kreismittelpunkt};
\pic[draw=black!70,text=black!70, -,"$\delta$", angle eccentricity=1.3] {angle= B--C--A};
\pic[draw=black!70,text=black!70, -,"$\alpha$"] {angle = K2--C--B};
\pic[draw=black!70,text=black!70, -,"$\alpha$"] {angle = C--B--K2};

\pic[draw=black!70,text=black!70, -,"$\beta$"] {angle = A--B--C};
\pic[draw=black!70,text=black!70, -,"$\beta$"] {angle = K2--B--K1};

\pic[draw=black!70,text=black!70, -,"$\gamma$"] {angle = K1--K2--C};
\pic[draw=black!70,text=black!70, -,"$\gamma$"] {angle = B--K1--K2};

\pic ["\Huge $\cdot$", draw, -] {angle=C--A--B};
\pic ["\Huge $\cdot$", draw, -] {angle=Kreismittelpunkt--A--C};}

Buy me coffee!

If my content has helped you, donate 3€ to buy me coffee. Thanks a lot, I appreciate it!



Fancy Headers and final Footers in LaTeX

This post explains advanced uses of headers and footers. The template changes between two fancy pagestyles and provides a TikZ based header and a – alsoTikZ based – final footer which only appears on the very last page of the document (which LaTeX will determine on its own without you setting it explicitly).


[Markdown is kind of broken in this post. Parts of it were repaired but other parts seem stubbornly broken (and break over and over again), so I decided that it will be ok to stay like this. If you’re interested in the information – it’s all here. It doesn’t look so good but that you should be able to survive πŸ˜‰ ]


This post is not intended for beginners who just want to make simple use of the basic fancyhdr features. A great explanation of these can be found in the ShareLaTeX tutorial (see “Resources” section below).

So if you don’t care to read the following (long) explanation of these advanced header / footer uses, just use my Overleaf template and come back here if you want to customize something to get information you need. All the facts are here.

You can find it here.  It’s a view-only share link to the template I created but I can’t publish it as a template via Overleafv2, so have fun with the link (hopefully this will be possible later). Just copy it as your own project or something.

The code can be found in full in the Overleaf template and has extensive comments. I will, however, explain all the snippets even more in detail in this post, so you can understand what I did and why I did it. Especially because the code to create this might be overwhelming to you in whole if you haven’t done a lot of advanced LaTeX customizing so far.

General settings for our document

This is the preamble, not a lot to explain here so far, so just the code:


\documentclass[10pt, a4paper]{article}

% Page Settings
\usepackage{geometry} % Allows the configuration of document margins
\geometry{includeheadfoot,a4paper, textwidth=0.87\paperwidth, textheight=0.8\paperheight}

\usepackage{lipsum} % provides lorem ipsum for testing

% Font Settings
\usepackage{lmodern} % http://www.tug.dk/FontCatalogue/latinmodernroman/
\usepackage[thin]{raleway} % different font for the TikZ header



And some further settings here:


% Settings for Fancy Headers and Footers

% Settings for TikZ Headers with coloured background

\usepackage[usenames, dvipsnames]{color} % https://de.sharelatex.com/learn/Using_colours_in_LaTeX#!#Reference_guide z.B. \color{RubineRed} - use ColorNames
\definecolor{CornflowerBlue}{RGB}{100,149,237} %#6495ed (HTML) - define your own colors
% pick some from here: http://latexcolor.com/



Setting header and footer with the fancyhdr package

Why is this chapter here? Didn’t I say I was not going to do the basic fancyhdr explanation? Yes, I did indeed. This is why you’ll just get the code snippet with its comments from Overleaf. What I did here is no sorcery and can be understood from the ShareLaTeX tutorial (see “Resources” below). I find that ShareLaTex generally does a great job in explaining the stuff you really need, even as an advanced user. It gives an overview on the most common packages without being as confusing as their package documentations. Definitely worth checking! ( https://www.sharelatex.com/learn )


% Settings for "normal" headers and footers
\usepackage{fancyhdr} % http://mirror.easyname.at/ctan/macros/latex/contrib/fancyhdr/fancyhdr.pdf

\fancyhf{} % clear space at the header and footer so the fancy headers / footers can be placed
\renewcommand{\headrulewidth}{2pt} % set a head rule of 2pt thickness
%\renewcommand{\footrulewidth}{1pt} % same would be possible if you wanted a footer rule

% things you might want to access here: \thesection \thechapter \chaptername \sectionmark \rightmark \leftmark
% check this for further info: https://en.wikibooks.org/wiki/LaTeX/Customizing_Page_Headers_and_Footers

% puts a small logo on the right side of the HEADER - same goes for the \lhead:
\lhead{\footnotesize\textbf{Example citation:} \textsc{Author-Lastname}, Surname: ``Article title'', in: \textsc{Editor} (ed.): \emph{booktitle}, NY 2018. {\textsc{Link:}} \protect\url{http://mylink.com}{ } \lbrack{}\today\rbrack{}.}
% you could you \chead to access the center as well

% defines all the FOOTER settings. But in this case, they are conditional: We check if we're on the last page and only print it, if we're not.
\lfoot{\ifnum\getpagerefnumber{VeryLastPage}=\value{page}\else{\scriptsize your custom footer text goes here}\fi}

% add the page count in the middle: \thepage gives you the current page, \pageref{LastPage} the total



If the part where the if conditions turn up in the footer settings confuse you, don’t worry. I will explain this in the final footer part.


Creating the final footer

Using hooks to find the last page of a document

Finding the last page of a document in LaTeX is not as trivial as it might seem. Sometimes, you might succeed just using \AtEndDocument. But this will only work if the contents of the last page have not been shipped out before LaTeX realizes it needs to check if it’s the last page. Sometimes, this will work just fine. Other times, all the content is already printed once you reach this point. This is why we need the atveryend package which will help us find the real last page of our document by setting some more page hooks after the \AtEndDocument is executed and after the last shipout is done.

In our example, we trigger this behaviour in the fancyhdr part where we check if we’re on the last page. Then, we don’t want fancyhdr to print the footer. Because now, our footer background will executed: That’s right – our final footer is actually a TikZ-based background setting which is only applied to the last page where we disabled the fancyhdr footer.

Having used \usepackage[pages=some]{background}, we could also invoke this background manually anywhere we want like this: \BgThispage. This, however, I found a bit tedious. I wanted to automatically create LaTeX output from XML files using XSLT transformation. So, of course, I wouldn’t be able to manually add \BgThispage at every document’s last page. First of all, because it’s tedious and then, how do you even know where this is if you don’t typeset all the pagebreaks by hand? So I came up with the solution presented here.

(I am not 100% sure, however, if this is the most elegant or failsafe solution possible – always happy to get your feedback!)


% packages for the custom header and footer

% different last page footer

% credit: https://tex.stackexchange.com/questions/120773/footer-on-last-page
\newcommand{\footercustomlastpage}[3]{% here a command is set
\backgroundsetup{% from the background package
contents={% contents then contain basically the same TikZ picture as I use for the header
\tikz[remember picture,overlay]{%
\fill[gray!70,ultra thick]%
([yshift=120pt]current page.south west)%
(current page.south east);%
\node[anchor=north west,inner sep=0pt,text width=.75\paperwidth,align=left] at ([yshift=15pt,xshift=50pt]current page.south west|-current page text area.south west) {#1};%
\node[anchor=north,inner sep=0pt,text width=.3\paperwidth,align=right] at ([yshift=-5pt,xshift=90pt]current page text area.south) {#2};%
\node[anchor=north east,inner sep=0pt,text width=.3\paperwidth,align=right] at ([yshift=-5pt,xshift=-30pt]current page.south east|-current page text area.south east) {#3};%

% I made a command for this, so you can put the above in an external file
% and only keep the actual contents of the footer in this main file
% making a new command would, of course, not been necessary
{\huge Jack Sparrow image credit: Walt Disney. Thanks, mate!}

%--------------------------------------------------------------------------------- End footer placement
% here we determine that the footer (which really is a background constisting of TikZ picture
%will be printed on the very last page only




A possible problem with this solution might be that I never use \thispagestyle{empty}, so your content could possibly overflow into the footer, if the last page is very full. Usually it doesn’t do that and if it does, it can usually be avoided by rearranging the last few pages a little bit. When you don’t do automated transformations like I did, this shouldn’t bother you much. Also, with the geometry settings I used, I found that it wasn’t much of a problem and only a tiny bit visible when I, for example, excessively used footnotes on the last page.

If you want to absolutely ensure that your header and footer are cleared, you have to use  \thispagestyle{empty}, which will overwrite  \pagestyle{fancy} we set at the beginng, but for the current page only. Mind you though, this will not only affect the footer section but cause you to have no header as well. This is why I don’t do it and accept some minor overflow as the tradeoff.

\thispagestyle{plain} will remove the header and footer for one page but at least will keep the page numbering in the footer, by the way. Non-fancy, LaTeX automatically created centered page numbering, that is. So no “page 3 of 3”. Just “3”.

The header using a TikZ background

The header command I created resembles the footer in the way that it is also a TikZ background, only this time it’s not set to be transparent (like above) and it’s at the top of the page. This time, I also want to be able to use this for every page I want, whenever I want. (We could configure it as a replacement / version of \maketitle which some people do in custom CV templates, but I prefer it this way. It keeps me in control of my document.) While the footer just has three textareas you can fill as you please, the header has one circle for a picture and three spots for text. It’s a header I configured for a CV template, so feel free to make your own version of this header command to fit your needs.


% inspired by: https://www.sharelatex.com/templates/cv-or-resume/fancy-cv
\tikz[remember picture,overlay] {%
\node[rectangle, fill=#5, anchor=north, minimum width=\paperwidth, minimum height=5cm](header) at (current page.north){};%
\node[left=#7 of header.north, anchor=east](name) at (header.east) {\fontfamily{\sfdefault}\selectfont #2};%
\node[anchor=south east](degree) at (name.north east) {\fontfamily{\sfdefault}\selectfont\flushright #1};%
\node[anchor=north east](descr) at (name.south east) {\fontfamily{\sfdefault}\selectfont #3};%
\node[right=#6 of header.west, anchor=west](picture) at (header.west) {};%
\draw[path picture={\node[anchor=center] at (path picture bounding box.center){\includegraphics[height=4.3cm]{#4}} ;}] (picture) circle (2) ;}%


For this command to work, I had to ensure there was more than one fancy pagestyle available because we don’t want a normal header displayed when using this special one. Also, the special header needs some tweaking with geometry etc. because it’s larger and in the fancyhdr package, we have the problem that the footer will disappear when \headheight becomes too large. In our case, large means 5cm – that’s too large for fancyhdr.

So we set a new geometry locally for the page the header command is used on and restore it afterwards. We also activate the pagestyle for these pages only by using \thispagestyle{header} instead of \pagestyle{header}.


\newgeometry{includeheadfoot,a4paper, textwidth=0.87\paperwidth, textheight=0.7\paperheight, top=3cm, headheight=0cm, headsep=0cm}

\fancyhf{} % clear space at the header and footer again
\renewcommand{\headrulewidth}{0pt} % get rid of the headrule

% defines all the FOOTER settings to work as above.
% We still check if we're on the last page and only print it, if we're not.
\lfoot{\ifnum\getpagerefnumber{VeryLastPage}=\value{page}\else{\scriptsize your custom footer text goes here}\fi}

% add the page count in the middle: \thepage gives you the current page, \pageref{LastPage} the total


Styling the header

\fontfamily{\sfdefault}\selectfont selects the raleway font we loaded in the preamble. This is just because I thought it looked good. Do whatever you want.

The command takes a background colour as one argument, the three textareas, the image location and two centimenter values for the placement of the image circle and the texts in the header. The first three arguments are the text areas.

By the way (did I mention this already?), this header command comes from a custom CV template I created. I will show it to you as soon as I’m fully happy with it. But so far, suffice it to say that it was inspired by the friggeri-cv class (as always, see “Resources” for links).