13

I'm desperately searching for a way to recreate those really nice inline-tcboxes they used in tcolorbox manual for, as an example, emphasizing libraries' names.

enter image description here

I found some topics about left-sided + rotated titles but I can't find a way to adapt the aswers to this specific goal.

Does anyone have a clue ?

1 Answer 1

17

Copied from tcolorbox's documentation:

\documentclass{article}

\usepackage{lipsum}
\usepackage[skins]{tcolorbox}
\usepackage{hyperref}

\newtcbox{\mylib}{enhanced,nobeforeafter,tcbox raise base,boxrule=0.4pt,top=0mm,bottom=0mm,
  right=0mm,left=4mm,arc=1pt,boxsep=2pt,before upper={\vphantom{dlg}},
  colframe=green!50!black,coltext=green!25!black,colback=green!10!white,
  overlay={\begin{tcbclipinterior}\fill[green!75!blue!50!white] (frame.south west)
    rectangle node[text=white,font=\sffamily\bfseries\tiny,rotate=90] {LIB} ([xshift=4mm]frame.north west);\end{tcbclipinterior}}}

\MakeRobust\mylib

\ifdefined\pdfstringdefDisableCommands
  \pdfstringdefDisableCommands{\def\mylib#1{'#1'}}
\fi

\begin{document}

Library \mylib{lipsum}:

\lipsum[1]

\end{document}

enter image description here

The line \MakeRobust\mylib makes \mylib robust, so that you can use it in the argument of commands like \section or \caption. The line \pdfstringdefDisableCommands (used only if hyperref is loaded) makes \mylib produce a sensible PDF outline entry when used in \section. If you then do \section{Library \mylib{lipsum}} it won't break (because of \MakeRobust), and the PDF outline will say Library 'lipsum'.

5
  • I get undefined control sequence in XeTeX when trying this (\pdfstringdefDisableCommands). Also, explaining what is actually happening in the code would help greatly for debugging purposes.
    – Ole Aldric
    Feb 12, 2021 at 11:50
  • @OleAldric \pdfstringdefDisableCommands is from hyperref, so I assume you are not loading it, thus the error. Just remove that line and it should work. I don't know what each option does (back then I copied from the manual, and these days I know less of tcolorbox than I did then :), but other than that the code is straightforward: load packages, define \newtcbox\mylib, then \robustify{\mylib} makes \mylib robust so it doesn't break when used in a \section (for example), and the \pdfstringdefDisableCommands line makes it produce a sensible PDF outline when used in \section. Feb 12, 2021 at 12:17
  • @OleAldric I added some explanation Feb 12, 2021 at 12:29
  • Upvoted, I do have hyperref enabled, but I use this in a class so maybe that causes some havoc. I will research this further. The text in the main box is also ever so slightly offset vertically. Not sure what is going on there, but I guess I need to dive into the documentation for that.
    – Ole Aldric
    Feb 12, 2021 at 12:32
  • @OleAldric lipsum looks aligned with the baseline of the text to me (but that is done by the tcolorbox options, so sorry, I can't help you there). Feel free to ask a question. Re: hyperref: \pdfstringdefDisableCommands must be after hyperref is loaded, so if you're doing it in a class file you may want to do it in \AtBeginDocument{...} Feb 12, 2021 at 12:39

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.