3

I have change the \chapter section definition but in some chapters of the book I don't want to apply it. For example, in the code below I don't want to apply in \EjerPro. How can I do it?

\documentclass[openany]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[spanish,es-lcroman]{babel}
\usepackage[hmargin=2cm,tmargin=4cm,bmargin=2.5cm,centering]{geometry}
\usepackage[demo]{graphicx}
\usepackage{kpfonts}
\usepackage[pagestyles,explicit]{titlesec}
\usepackage{xcolor}
\usepackage{polynom}
\usepackage{enumitem}
\usepackage[absolute]{textpos}
\usepackage{lipsum}

\definecolor{seccolor}{RGB}{255,204,102}% para las secciones
\definecolor{ssseccolor}{RGB}{255,233,190}% para las subsubsecciones
\definecolor{probcolor}{RGB}{159,209,139}% para los problemas
\definecolor{rptacolor}{RGB}{214,234,204}% para las respuestas

\newcommand\EjerPro{%
\chapter*{\colorbox{probcolor}{\parbox{\dimexpr\linewidth-6pt}{\hfil \LARGE\strut EJERCICIOS Y PROBLEMAS\hfil}}}
}


\usepackage{tikz}
\usepackage{kpfonts}
\usepackage[explicit]{titlesec}

\newcommand*\chapterlabel{}
\titleformat{\chapter}
  {\gdef\chapterlabel{}
   \normalfont\sffamily\Huge\bfseries\scshape}
  {\gdef\chapterlabel{\thechapter\ }}{0pt}
  {\begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-3cm] at (current page.north west)
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=seccolor] (0,0) %rectangle
          (\paperwidth,3cm);
        \node[anchor=east,xshift=.9\paperwidth,rectangle,
            inner sep=11pt,
              fill=seccolor]
              {\color{black}\chapterlabel#1};
       \end{tikzpicture}
      };
   \end{tikzpicture}
 }
\titlespacing*{\chapter}{0pt}{50pt}{-60pt}

\begin{document}

\chapter{Expresiones algebraicas}
\lipsum[1-5]

\EjerPro
\lipsum[1-5]

\end{document}
0
3

One possibility is to locally apply the standard settings (which can be found on Section 9.2. Standard Classes of the titlesec documentation) to the desired chapters; this can be done directly or using a command, as in the example below:

\documentclass{book}
\usepackage[spanish,es-lcroman]{babel}
\usepackage[explicit]{titlesec}
\usepackage{tikz}
\usepackage{lipsum}

\definecolor{seccolor}{RGB}{255,204,102}% para las secciones
\definecolor{probcolor}{RGB}{159,209,139}% para los problemas

% Para capítulos con formato normal
\newcommand\regularchapter{%
\titleformat{\chapter}[display]
  {\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}
  {20pt}{\Huge##1}
\titlespacing*{\chapter}
  {0pt}{50pt}{40pt}
}
% Para capítulos con formato modificado
\newcommand*\chapterlabel{}
\titleformat{\chapter}
  {\gdef\chapterlabel{}
   \normalfont\sffamily\Huge\bfseries\scshape}
  {\gdef\chapterlabel{\thechapter\ }}{0pt}
  {\begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-3cm] at (current page.north west)
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=seccolor] (0,0) %rectangle
          (\paperwidth,3cm);
        \node[anchor=east,xshift=.9\paperwidth,rectangle,
            inner sep=11pt,
              fill=seccolor]
              {\color{black}\chapterlabel#1};
       \end{tikzpicture}
      };
   \end{tikzpicture}
 }
\titlespacing*{\chapter}{0pt}{50pt}{-60pt}

\newcommand\EjerPro{%
  \begingroup
  \regularchapter
  \chapter*{\colorbox{probcolor}{\parbox{\dimexpr\linewidth-6pt}{\hfil \LARGE\strut EJERCICIOS Y PROBLEMAS\hfil}}}
  \endgroup
}

\begin{document}

\chapter{A Modified Numbered Chapter}
\EjerPro
\lipsum[3]
\chapter{Another Modified Numbered Chapter}

\end{document}
1
  • I'm exploring the titlesec package for get something similar, in my case I need to change the label Chapter (Capítulo using babel for Spanish) for Título but I don't know which variable should I modify.
    – Aradnix
    Dec 21 '14 at 6:52
1

In the case you are describing, with two different versions of chapters, I would likely define a new command \mychapter or \Chapter that does what your \titleformat call does, and leave the original \chapter alone.

Here is what I did when I had a similar problem:

\newcommand{\mychapter}[1]{
 \chapterimage{#1}
 \chapter*{#1}
 \stepcounter{chapter}
 \addcontentsline{toc}{chapter}{#1}
 \chaptermark{#1}
 \label{#1}}

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.