I would like to have my tcolorbox, which is smaller than the surrounding running text, be positioned towards the right page margin. Is there a way to do this?
I've included my current MWE and a screenshot of what I mean for clarity:
\documentclass[a4paper]{article}
\usepackage{tcolorbox}
\usepackage{fontawesome5}
\usepackage{lipsum}
% ---------------------------------------------------------------------------- %
\newtcolorbox{importantbox}[2][]{
width=0.9\textwidth,
colback=white,
colframe=yellow,
coltitle=black,
fonttitle=\bfseries,
title=\faIcon{exclamation-triangle}~Caution: #2,#1
}
% ---------------------------------------------------------------------------- %
\begin{document}
\lipsum
\begin{importantbox}{Lorem Ipsum}
\lipsum
\end{importantbox}
\end{document}
Best Answer
You can use options
before
andafter
to print it inside aflushright
environment:BTW: For centering you can use
center
instead offlushright
.Almost the same, but with less vertical space above and below, can be done using option
flush right
:But if you don't want the extra vertical space above and below, you can alternatively use
before=\hfill
orbefore=\hspace*{\fill}
: