# Tcolorbox in footer with nobeforeafter adds space to other elements in footer

EDIT:

\documentclass[10pt]{article}
\usepackage{geometry}
\usepackage[skins]{tcolorbox}
\usepackage{fancyhdr}
\fancypagestyle{document}{
\renewcommand{\footrulewidth}{2pt}
\rfoot{  \raisebox{\dimexpr(-\height+\ht\strutbox-\dp\strutbox)/2}{%
\begin{tcolorbox}[nobeforeafter,
width=.3\linewidth,
frame hidden,boxrule=0pt,
colback=white,
freelance,
arc=0pt,
outer arc=0pt,
boxrule=0pt,
frame code={
\draw[blue,line width=2.5pt]
([xshift=-1.25pt]frame.north west) -- ([xshift=-1.25pt]frame.south west);
}
]\hfill Naar Index~$\rightarrow$ \end{tcolorbox}}}
\lfoot{\raisebox{\dimexpr(-\height+\ht\strutbox-\dp\strutbox)/2}{%
\begin{tcolorbox}[nobeforeafter,
width=.3\linewidth,
frame hidden,boxrule=0pt,
colback=white,
freelance,
arc=0pt,
outer arc=0pt,
boxrule=0pt,
frame code={
\draw[blue,line width=2.5pt]
([xshift=1.25pt]frame.north east) -- ([xshift=1.25pt]frame.south east);
}
]$\leftarrow$~Inhoudsopgave\hfill\end{tcolorbox}}}
}
\begin{document}
\thispagestyle{document}
.
\end{document}


I still have the same problem. The code above outlines the issue: the bars don't align.

EDIT: the bars didn't align because I missed a \strut before the actual text.

When I use a tcolorbox with nobeforeafter inside my footer, the rest of the footer jumps downward. How to stop this from happening?

\documentclass[10pt]{article}
\usepackage{fancyhdr}
\usepackage{tcolorbox}
\fancypagestyle{plain}{
\renewcommand{\footrulewidth}{1pt}
\rfoot{\begin{tcolorbox}[nobeforeafter,width=.3\linewidth]text\end{tcolorbox}}
\lfoot{text}
}
\begin{document}
\thispagestyle{plain}
text
\end{document}


• You can use the option baseline=5mm for instance. You should first calculate the height of your box with the text. – pluton May 18 '14 at 15:49

No need to guess: leave the measurements to TeX.

If you want the text in the tcolorbox to be aligned to the other text in the footer, then

\documentclass[10pt]{article}
\usepackage{fancyhdr}
\usepackage{tcolorbox}
\fancypagestyle{plain}{%
\renewcommand{\footrulewidth}{1pt}%
\fancyfoot[R]{\myfancyfoot{teyt}}%
\fancyfoot[L]{text}%
}

\newcommand{\myfancyfoot}[1]{%
\raisebox{\dimexpr(-\height+\ht\strutbox-\dp\strutbox)/2}{%
\begin{tcolorbox}[nobeforeafter,width=.3\linewidth]
\strut #1
\end{tcolorbox}}%
}

\begin{document}
\thispagestyle{plain}
text
\end{document}


If, instead, you want the top line of the tcolorbox to be level with the height of the other elements, then

\documentclass[10pt]{article}
\usepackage{fancyhdr}
\usepackage{tcolorbox}
\fancypagestyle{plain}{%
\renewcommand{\footrulewidth}{1pt}%
\fancyfoot[R]{\myfancyfoot{teyt}}%
\fancyfoot[L]{text}%
}

\newcommand{\myfancyfoot}[1]{%
\raisebox{\dimexpr -\height+\ht\strutbox}{%
\begin{tcolorbox}[nobeforeafter,width=.3\linewidth]
#1
\end{tcolorbox}}%
}

\begin{document}
\thispagestyle{plain}
text
\end{document}


You can raise the box by the amount needed to put the other text where you want to:

\documentclass[10pt]{article}
\usepackage{fancyhdr}
\usepackage{tcolorbox}
\fancypagestyle{plain}{
\renewcommand{\footrulewidth}{1pt}
\rfoot{\begin{tcolorbox}[tcbox raise=-.7cm,nobeforeafter,width=.3\linewidth]text\end{tcolorbox}}
\lfoot{text}
}
\begin{document}
\thispagestyle{plain}
text
\end{document}


Change the tcbox raise value as needed.

• This almost did the trick. See my edit in the OP. – 1010011010 May 18 '14 at 16:07
• @1010011010 See if egreg answer solves your problem, otherwise you should post a more accurate mwe to work with. – Nico Boni May 18 '14 at 16:14
• I'll post the full thing. – 1010011010 May 18 '14 at 16:15
• Second solution of the post down below solved it, but I had to manually adjust the bounding box. See i.imgur.com/xYnvnFP.png – 1010011010 May 18 '14 at 16:23
• Oh well, now the post is "up above", but that's still fine :) – Nico Boni May 18 '14 at 16:29