3

I'm trying to recreate this info box, but I'm having trouble making optional arguments for the title of the box and the position of the title. This is what I have so far. Aesthetically it is almost perfect, except the title isn't centered with the icon with the icon. Though this isn't really the main problem, just a "nice to have". The following is the code I used for the box:

\RequirePackage[most]{tcolorbox}
\RequirePackage{fontawesome}

\definecolor{tipsColor}{RGB}{142, 68, 173}

\makeatletter
\newtcolorbox{tipNote}[1][]{%
  enhanced jigsaw,
  borderline west={2pt}{0pt}{tipsColor},
  sharp corners,
  boxrule=0pt,
  fonttitle={\large\bfseries},
  coltitle={black},
  title={\textcolor{tipsColor}{\huge\faLightbulbO} Tip\\},
  attach title to upper,
  right=0pt,
  top=0pt,
  bottom=0pt,
  frame hidden,
  baseline={\tcb@height-2\kvtcb@boxsep+\baselineskip-2\lineskip},
  #1
}
\makeatother

\endinput    

This is how I call it:

\begin{tipNote}
\blindtext
\end{tipNote}

and it works fine. But I want to be able to have optional custom titles so I can call it like above and have the default title, or do one of the following and have a custom title:

\begin{tipNote}{Example}
\blindtext
\end{tipNote}

\begin{tipNote}[Example]
\blindtext
\end{tipNote}

Here's my attempt to get a custom title:

\makeatletter
\newtcolorbox{tipNote}[2][Tip]{%
  enhanced jigsaw,
  borderline west={2pt}{0pt}{tipsColor},
  sharp corners,
  boxrule=0pt,
  fonttitle={\large\bfseries},
  coltitle={black},
  title={\textcolor{tipsColor}{\huge\faLightbulbO} #2\\},
  attach title to upper,
  right=0pt,
  top=0pt,
  bottom=0pt,
  frame hidden,
  baseline={\tcb@height-2\kvtcb@boxsep+\baselineskip-2\lineskip},
  #1
}
\makeatother

and here's the error I get:

! Package pgfkeys Error: I do not know the key '/tcb/Tip' and I am going to ignore it. Perhaps you misspelled it.

See the pgfkeys package documentation for explanation.

How do I fix this? If I am doing it wrong what is the correct way to do this?

Edit: Here is a complete example of the .sty file in use:

\documentclass{article}

\usepackage{notes} % name of package with note boxes
\usepackage{blindtext}

\begin{document}

\begin{tipNote}
\blindtext
\end{tipNote}

\end{document}

Here is the complete .sty file, for reference.

0

1 Answer 1

2

Your example does almost what you want.

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{fontawesome,blindtext}

\definecolor{tipsColor}{RGB}{142, 68, 173}

\makeatletter
\newtcolorbox{tipNote}[1][Tip]{%
  enhanced jigsaw,
  borderline west={2pt}{0pt}{tipsColor},
  sharp corners,
  boxrule=0pt,
  fonttitle={\large\bfseries},
  coltitle={black},
  title={\textcolor{tipsColor}{\huge\faLightbulbO} #1\\},
  attach title to upper,
  right=0pt,
  top=0pt,
  bottom=0pt,
  frame hidden,
  baseline={\tcb@height-2\kvtcb@boxsep+\baselineskip-2\lineskip}
}
\makeatother
\begin{document}
\begin{tipNote}[Example]
\blindtext
\end{tipNote}

\begin{tipNote}
Always be nice to marmots!
\end{tipNote}

\end{document}

enter image description here

However, I'd go for a more flexible version in which you can add the title and more optional options.

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{fontawesome,blindtext}

\definecolor{tipsColor}{RGB}{142, 68, 173}

\makeatletter
\tcbset{my title/.store in=\mytitle,my title={Tip}}
\newtcolorbox{tipNote}[1][]{%
  enhanced jigsaw,
  borderline west={2pt}{0pt}{tipsColor},
  sharp corners,
  boxrule=0pt,
  fonttitle={\large\bfseries},
  coltitle={black},
  title={$\vcenter{\hbox{\textcolor{tipsColor}{\huge\faLightbulbO}}}~\vcenter{\hbox{\mytitle}}$\\},
  attach title to upper,
  right=0pt,
  top=0pt,
  bottom=0pt,
  frame hidden,
  baseline={\tcb@height-2\kvtcb@boxsep+\baselineskip-2\lineskip},
  #1
}
\makeatother
\begin{document}
\begin{tipNote}[my title=Example]
\blindtext
\end{tipNote}

\begin{tipNote}[borderline east={2pt}{0pt}{red!75!black},top=5pt,bottom=5pt]
Always be nice to marmots!
\end{tipNote}

\begin{tipNote}[borderline east={2pt}{0pt}{red!75!black},top=5pt,bottom=5pt,my
title=Another tip]
Also be friendly to ducks!
\end{tipNote}

\begin{tipNote}[borderline east={2pt}{0pt}{blue},top=5pt,bottom=5pt]
Always be nice to koala bears!
\end{tipNote}
\end{document}

enter image description here

1
  • 1
    @Antidisestablishmentarianism I added a second possibility which is IMHO better. There you can chance all sort of things (colors etc.) in the usual way, i.e. you do not have to give up the flexibility. The only downside: You need to write my title=<title>.
    – user121799
    Sep 9, 2018 at 0:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .