1

Inspired by this question and answer I was looking to create a convenient command for a titled sidebar of variable width.

Thus far I have solved half the problem. The following code gives a title, but I haven't yet got the variable width worked out...

\documentclass{article}
\usepackage{wrapfig}
\usepackage{tcolorbox}
\usepackage{lipsum}

\newenvironment{SideBox}[1]
  {\wrapfigure{#1}{0.5\textwidth} \tcolorbox[title=#1]}
  {\endtcolorbox\endwrapfigure}

\begin{document}

\begin{SideBox}{A fancy title}
  text inside the box
\end{SideBox}
\lipsum[2]

\end{document}

Any suggestions on how to improve the code to get variable width via a command like:

\begin{SideBox}{0.3}{A fancy title}
  text inside the box
\end{SideBox}

Thanks for any help.

1

Something like this?

\documentclass{article}
\usepackage{wrapfig}
\usepackage{tcolorbox}
\usepackage{lipsum}

\newenvironment{SideBox}[3][]
  {\wrapfigure{#3}{#2\textwidth} \tcolorbox[title=#3,width={#2\textwidth},#1]}
  {\endtcolorbox\endwrapfigure}

\begin{document}

\begin{SideBox}[colbacktitle={yellow},colback={white!70!yellow},coltitle={black},fonttitle={\large\bfseries}]{0.3}{A fancy title}
  text inside the box
\end{SideBox}
\lipsum[2]

\end{document}

enter image description here

**Some 'improvements' **

\documentclass{article}
\usepackage{wrapfig}
\usepackage[most]{tcolorbox}

\usepackage{lipsum}

\newtcolorbox{mysidebox}[1][]{%
  nobeforeafter,
  colbacktitle={yellow},
  colback={white!70!yellow},
  coltitle={black},
  fonttitle={\large\bfseries},
  #1,
}

\newenvironment{SideBox}[4][]
  {\wrapfigure{#4}{#2\textwidth}\mysidebox[title=#3,width={#2\textwidth},#1]}
  {\endmysidebox\endwrapfigure}

\begin{document}

\begin{SideBox}{0.3}{A fancy title}{r}
  text inside the box
\end{SideBox}
\lipsum[2]

\begin{SideBox}[enhanced,sharp corners,drop shadow={green}]{0.4}{A fancy title}{l}
  text inside the box
\end{SideBox}
\lipsum[2]


\end{document}
3
  • Q: I saw the pre-edit version with \newenvironment{SideBox}[2]. What was the value of extending this to 3 input params? Is that to facilitate other options (like being yellow) when calling sidebox? – Mark_Anderson Mar 13 '17 at 19:17
  • @Mark_Anderson: I have thought about the possibility of changing the tcolorbox options, which are given as first optional argument, i.e. \SideBox[options for tcolorbox]{width}{Title} – user31729 Mar 13 '17 at 19:20
  • I've used wrapfigure wrong, however – user31729 Mar 13 '17 at 19:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.