2

I want to retouch the behavior of \paragraph but something is bad in my code, Can anybody help me?

\documentclass[12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[pdftex]{graphicx}
\usepackage[table]{xcolor}
\usepackage{sectsty}
\renewcommand{\thesection}{{\color{black!80} \thechapter-\arabic{section}}}
  \makeatletter
  \renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}{-3.25ex \@plus -1ex \@minus -.2ex}{1.5ex \@plus .2ex}{\sffamily\normalsize\bfseries}}
  \makeatother
\chapterfont{\thispagestyle{empty}\huge \sffamily \color{blue!50!black}\raggedleft}
\sectionfont{\sffamily}
\subsectionfont{\fcolorbox{blue!80}{blue!80}{\phantom{XXX}} \color{blue}\sffamily}
\subsubsectionfont{\fcolorbox{green!80}{green!80}{\phantom{XX}}\phantom{X} \color{green!50!black}\sffamily}
\paragraphfont{\fcolorbox{red!50!black}{red!50!black}{\phantom{XXX}}\phantom{XXX} \color{white}\sffamily}

\begin{document}
    \chapter{este capítulo}
    cap
    \section{en la sección}
    escribiendo
    \subsection{subsección}
    mas todavia
    \subsubsection{subsub}
    y finalmente    
    \paragraph{que un párrafo}
    no funciona
\end{document}   
  • 1
    \renewcommand{\paragraph} is clashing with \paragraphfont. Moreover, why use \color{white} in \paragraphfont? That hides the paragraph title when the redefinition of \paragraph is commented out. – Masroor Aug 26 '17 at 16:33
  • 2
    The redefinition of \paragraph should occur before you load sectsty. – Mico Aug 26 '17 at 16:33
  • Yes, @Masroor, my mistake. originally my code was "viol" and previously defined. – JOM Aug 28 '17 at 19:11
3

When working with the sectsty package, it's generally a good idea to undertake any redefinitions of \section, \subsection, etc before loading sectsty and issuing instructions such as \chapterfont, \sectionfont, etc.

A separate issue: In your definition of \paragraphfont, the directive \color{white} serves to make the string "que un párrafo" (the argument of \paragraph) invisible. Change the directive to \color{orange}, say, to verify this claim.

enter image description here

\documentclass[12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[pdftex]{graphicx}
\usepackage[spanish]{babel}
\usepackage[table]{xcolor}

%\setcounter{secnumdepth}{4} % uncomment this, if desired

\renewcommand{\thesection}{%\color{black!80} 
    \thechapter-\arabic{section}}
\makeatletter
  \renewcommand{\paragraph}{\@startsection{paragraph}%
    {4}{\z@}{-3.25ex \@plus -1ex \@minus -.2ex}%
    {1.5ex \@plus .2ex}{\sffamily\normalsize\bfseries}}
\makeatother

\usepackage{sectsty}
\chapterfont{\thispagestyle{empty}\huge \sffamily \color{blue!50!black}\raggedleft}
\sectionfont{\sffamily}
\subsectionfont{\fcolorbox{blue!80}{blue!80}{\phantom{XXX}} \color{blue}\sffamily}
\subsubsectionfont{\fcolorbox{green!80}{green!80}{\phantom{XX}}\phantom{X} \color{green!50!black}\sffamily}
\paragraphfont{\fcolorbox{red!50!black}{red!50!black}{\phantom{XXX}}\phantom{XXX} \color{orange}\sffamily}

\begin{document}
    \chapter{este capítulo}
    cap
    \section{en la sección}
    escribiendo
    \subsection{subsección}
    mas todavia
    \subsubsection{subsub}
    y finalmente    
    \paragraph{que un párrafo}
    ahora funciona bien
\end{document} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.