tcolorbox: come creare una variante del mylib
Aug 16 2020
Questa domanda :
Come riprodurre questa scatola in tcolorbox
ha una risposta chiara. Volevo creare una variante simile con due piccole modifiche:
-invece di LIB, usa REMARKS (ok, è banale)
-formattare il testo in elenchi puntati (ambiente dettagliato)
\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}}}
fallirà su questo:
\remarks
{
\item Perfect relationships of $r=\pm1$ do not exist in the real world.
\item Correlation does not imply causation
}
non riesce a notare un elemento mancante, quindi è in corso una sorta di problema di analisi.
È probabile che il modo ideale per farlo sia modificare direttamente newtcbox in modo che formatta il testo nell'elemento, ma non so nemmeno da dove cominciare.
Risposte
2 muzimuzhiZ Aug 17 2020 at 05:05
Prova questo:
- L'opzione
varwidth upper=\linewidth
viene utilizzata (con ilvarwidth
pacchetto caricato) per consentire\myremarks
di comporre il suo argomento in modalità paragrafo, richiestaitemize
dall'ambiente. Questo è equivalente a\myremarks{\begin{varwidth}{\linewidth} ...\end{varwidth}}
. - Poiché il testo ruotato
REMARKS
è maggiore dell'altezza minima di\myremarks
, l'opzioneheight from=1.2cm to \maxdimen
viene utilizzata per impostare un'altezza minima. - Le opzioni del nodo
pos=1, anchor=south east
vengono aggiunte per allegare il testoREMARKS
in alto, anziché centrato verticalmente. enumitem
le opzioninoitemsep, leftmargin=5mm
sono per la regolazione degli spazi diitemize
.
\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}
