2

I defined my own tcolorbox as in the following MWE but I would like to put inside the tcolorbox a default title and change it a will.

For example if I write

    \begin{notabene}
        \lipsum[1]
    \end{notabene}

the box should show the default title "Remarks", but if I write:

    \begin{notabene}{NB}
        \lipsum[1]
    \end{notabene}

the box should have the title "NB".

I have read the tcoulorbox manual but I didn't succeed to understand how to do that!

Thanks in advance for your eventual help.

Nino

\documentclass[justified,notoc,numbers]{tufte-handout}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{color}
\usepackage[most]{tcolorbox}

%-----------FOR DEMO-----------
\usepackage{lipsum}

\definecolor{myColor}{rgb}{0.0, 0.5, 1.0}
\newtcolorbox{notabene}[2][]
{
    breakable,
    enhanced,
    borderline west={2pt}{0pt}{myColor},
    sharp corners,
    boxrule=0pt,
    fonttitle={\large\bfseries},
    coltitle={black},
    title= {\textcolor{myColor}{#2}\\},
    attach title to upper,
    right=0pt,
    top=0pt,
    bottom=0pt,
    frame hidden,
    #1,
}

%=======================================================
%                       DOCUMENT
%=======================================================
\begin{document}
    \begin{notabene}
        \lipsum[1]
    \end{notabene}
    \begin{notabene}{NB}
        \lipsum[1]
    \end{notabene}

\end{document}
3
  • Welcome! I don't see how you can expect TeX to read your mind ;). If you give it identical code, it's not unreasonable to expect identical results. Indeed, that's generally thought to be a point in a system's favour. I suspect you missed something from your question.
    – cfr
    Commented Oct 28, 2023 at 4:51
  • 1
    You currently have \begin{env}[<optional arg>]{<required arg>}. If you want to make the required argument into an optional argument, the syntax will be ambiguous. In particular, you'd have to write \begin{notabene}[][Non-Default] if you wanted to use a non-default title but otherwise stick to the default settings, because \begin{notabene}[Non-Default] will be interpreted as an attempt to set the key Non-Default. So what should the interface look like?
    – cfr
    Commented Oct 28, 2023 at 4:57
  • @cfr thanks for your help, but I’m not so stupid to expect TeX to read your mind ;) I posted my question late at night so I extracted the MWE wrongly from my original document. Anyway I think it was not so difficult to understand what I meant ;) I’ve read your attempt to explain how should I do, but I’m unable to understand what you mean! :( Commented Oct 28, 2023 at 7:15

1 Answer 1

1

I found a solution!

\newtcolorbox{notabene}[1][]{
    enhanced,
    boxrule=0pt,frame hidden,
    borderline west={3pt}{0pt}{mycolor},
    colback=mycolor!5,
    title=Rimarkoj,
    coltitle=mycolor,
    attach title to upper={\ },
    fonttitle=\bfseries,
    sharp corners,
    #1
}

Default title:

\begin{notabene}
\limpsum[1]
\end{notabene}

New title:

\begin{notabene}[title=NB]
\limpsum[1]
\end{notabene}

Thanks.

You must log in to answer this question.

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