mattiaca” post=95528Salve, sto provando a costruire un comando che metta un box colorato alle spalle del titolo di una sezione.
ho provato con questo codice:`
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\definecolor{colorebox}{named}{green}
\newcommand{\boxsfondo}[1]{\fcolorbox{colorebox}{colorebox}{#1}}
\usepackage{lipsum}
\usepackage{titlesec}
\titleformat{\section}
{\LARGE\bfseries} % format
{} % label (the number)
{0pt} % separation between label and title
{\scshape
\boxsfondo{\sectiontitle}% % before
}
\begin{document}
\title{Un documento}
\author{io}
\maketitle\section{QUesto è il titolo della section con colore colorebox}
\subsection{\fcolorbox{red}{red}{questo titolo è in un box rosso}}\lipsum[1]
\end{document}
`il risultato non è però quello voluto. Cosa fare?
Puoi usare [tt]varwidth[/tt]
`\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage[T1]{fontenc}
\usepackage{xcolor,varwidth}
\usepackage{titlesec}
\definecolor{colorebox}{named}{green}
\newcommand{\boxsfondo}[1]{%
\fcolorbox{colorebox}{colorebox}{%
\begin{varwidth}{\textwidth}\raggedright
#1
\end{varwidth}%
}%
}
\titleformat{\section}
{\LARGE\bfseries} % format
{} % label (the number)
{0pt} % separation between label and title
{\scshape\boxsfondo} %
\begin{document}
\title{Un documento}
\author{io}
\maketitle
\section{Questo è il titolo della section con colore colorebox}
\end{document}`
Ciao
Enrico