tcolorbox: como fazer uma variante do mylib

Aug 16 2020

Essa questão :

Como reproduzir esta caixa em tcolorbox

tem uma resposta clara. Eu queria fazer uma variante semelhante com duas pequenas mudanças:

-em vez de LIB, use REMARKS (ok, isso é trivial)

-formatar o texto em marcadores (itemizar o ambiente)

\newtcbox{\myremarks}{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] {REMARKS} ([xshift=4mm]frame.north west);\end{tcbclipinterior}}}


\NewDocumentCommand\remarks{m} 
{\myremarks{\begin{itemize} #1\end{itemize}}}

falhará nisso:

\remarks
{
\item Perfect relationships of $r=\pm1$ do not exist in the real world.
\item Correlation does not imply causation
}

falha ao notar um item ausente, então há algum tipo de problema de análise acontecendo.

É provável que a maneira ideal de fazer isso seja modificar o newtcbox diretamente para que formate o texto no itemize, mas eu nem sei por onde começar.

Respostas

2 muzimuzhiZ Aug 17 2020 at 05:05

Experimente isto:

  • A opção varwidth upper=\linewidthé usada (com o varwidthpacote carregado) para permitir \myremarksa composição de seu argumento no modo de parágrafo, que é exigido pelo itemizeambiente. Isso é equivalente a \myremarks{\begin{varwidth}{\linewidth} ...\end{varwidth}}.
  • Como o texto girado REMARKSé mais alto do que a altura mínima de \myremarks, a opção height from=1.2cm to \maxdimené usada para definir uma altura mínima.
  • As opções de nó pos=1, anchor=south eastsão adicionadas para anexar texto REMARKSao topo, em vez de centralizado verticalmente.
  • enumitemas opções noitemsep, leftmargin=5mmsão para ajustar os espaços de itemize.
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{skins}

\usepackage{enumitem}
\usepackage{varwidth}
\usepackage{xparse}

\newtcbox{\myremarks}{
  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, pos=1, anchor=south east] {REMARKS}
        ([xshift=4mm]frame.north west);
    \end{tcbclipinterior}
  },
  % equivalent to surround the cmd arg in "varwidth" env
  varwidth upper=\linewidth,
  % set minimum height for complete output of rotated "REMARKS"
  height from=1.2cm to \maxdimen,
}

\NewDocumentCommand\remarks{m}{%
  \myremarks{%
    \begin{itemize}[noitemsep, leftmargin=5mm]
      #1%
    \end{itemize}
  }%
}

\begin{document}
\remarks{
  \item abc
}

\remarks{
  \item abc
  \item def
  \item ghi
}
\end{document}