Estoy intentando crear un documento de dos caras con KomaScript. Quiero agregar algo extra a cada página donde comienza una nueva sección. Empecé creando un nuevo estilo de página segúnesta publicación. Intenté modificar el ejemplo dado allí. Hasta ahora he hecho esto:
\documentclass[12pt,a4paper,ngerman, twoside]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[ngerman]{babel}
\usepackage[left=3.8cm,right=2.2cm,top=3cm,bottom=3cm]{geometry}
\usepackage{xcolor}
\usepackage[headsepline, automark]{scrlayer-scrpage}
\clearpairofpagestyles
\renewcommand*\pagemark{{\usekomafont{pagenumber}Seite\nobreakspace\thepage}}
\automark[section]{section}
\ihead*{\headmark}
\ohead*{\pagemark}
\chead{}
\cfoot[]{}
\ofoot[]{}
\ifoot[]{}
\newpairofpagestyles{highlights}{
\chead{}
\KOMAoptions{headsepline=false}
\ohead*{\colorbox{blue!15}{%
\makebox[\dimexpr\linewidth-2\fboxsep][l]{\color{white}%
\hfill
\pagemark}
}
}
}
\begin{document}
\section{Section 1}
Some text.
\cleardoublepage
\thispagestyle{highlights}
\section{Section 2}
Some text.
\end{document}
Esto da como resultado este estilo de encabezado:
Me gustaría lograr tres cosas:
Crear unestilo de página personalizadoen el MWE dado que puedo activar en páginas específicas (donde comienzan las nuevas secciones) que contiene la barra de colores (que especifico a continuación) y el número de página
Crea elbarra de colores con un degradado de color detrás del numerador de página en el encabezado(Sería bueno si la barra de colores opcionalmente también pudiera extenderse fuera de la región del encabezado en la dirección interna o externa, según el gusto)
Cambiar elEl color del texto del marcador de página será blanco., entonces tengo texto blanco delante de la barra de colores.
Para visualizar lo que busco, edité la página importante de mi MWE;esto es lo que deseo lograr:
Ya intenté crear un nuevo estilo de página de la siguiente manera, que también se sugirió en el enlace anterior. Sin embargo , no tengo suficiente experiencia tikz
para que funcione:
\usepackage{tikz}
\DeclareNewLayer[background,head,
contents={\hspace*{0cm}%
\tikz{
\fill[shade,left color=blue!0,right color=blue!20,right color=blue!70] (0,0)rectangle(20cm ,{1.4cm});
\node[rotate=0,font=\bfseries] at({\textwidth-0.9cm},{0})
{\ppagemark};
}}
]{highlights.bg}
\DeclareNewPageStyleByLayers{highlights}{highlights.bg}
Además, con este enfoque ni siquiera sé cómo conseguiría el número de página donde quiero.
Tal vez alguno de ustedes haya hecho esto antes o comprenda el asunto lo suficientemente profundo como para poder ayudarme.
Respuesta1
Desafortunadamente, no entiendo muy bien cuál se supone que debe ser el resultado deseado. Pero sugeriría definir una nueva capa para el fondo del encabezado:
\DeclareNewLayer[
background,
head,
hoffset=0pt,
width=\paperwidth,
mode=picture,
contents={\putLL{\tikz{
\ifodd \value{page}
\fill[shade,left color=blue!0,right color=blue!70]
(0,0)rectangle(\the\layerwidth,\the\layerheight);
\else
\fill[shade,left color=blue!70,right color=blue!0]
(0,0)rectangle(\the\layerwidth,\the\layerheight);
\fi
}}
}
]{highlights.bg}
Luego puedes agregar esta capa al comienzo de tu nuevo estilo de página definido:
\newpairofpagestyles{highlights}{
\ohead{\pagemark}
\KOMAoptions{headsepline=false}
\addtokomafont{pagenumber}{\bfseries\color{white}}
}
\AddLayersAtBeginOfPageStyle{highlights}{highlights.bg}
Ejemplo:
\documentclass[12pt,ngerman, twoside]{scrartcl}
\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc}% needed with older TeX distributions
\usepackage{lmodern}
\usepackage{babel}
\usepackage[left=3.8cm,right=2.2cm,top=3cm,bottom=3cm]{geometry}
\usepackage{tikz}% loads xcolor, graphicx etc.
\usepackage[headsepline]{scrlayer-scrpage}
\clearpairofpagestyles
\renewcommand*\pagemark{{\usekomafont{pagenumber}Seite\nobreakspace\thepage}}
\automark[section]{section}
\ihead{\headmark}
\ohead*{\pagemark}
\newpairofpagestyles{highlights}{
\ohead{\pagemark}
\KOMAoptions{headsepline=false}
\addtokomafont{pagenumber}{\bfseries\color{white}}
}
\DeclareNewLayer[
background,
head,
hoffset=0pt,
width=\paperwidth,
mode=picture,
contents={\putLL{\tikz{
\ifodd \value{page}
\fill[shade,left color=blue!0,right color=blue!70]
(0,0)rectangle(\the\layerwidth,\the\layerheight);
\else
\fill[shade,left color=blue!70,right color=blue!0]
(0,0)rectangle(\the\layerwidth,\the\layerheight);
\fi
}}
}
]{highlights.bg}
\AddLayersAtBeginOfPageStyle{highlights}{highlights.bg}
\usepackage{blindtext}% only for dummy text
\begin{document}
\section{Section 1}
Some text.
\cleardoublepage
\thispagestyle{highlights}
\blinddocument
\end{document}
Pero si cada sección de su documento debe comenzar en una nueva página impar, entonces puede cambiar a clase scrreprt
con la opción open=right
. Así que aquí hay una sugerencia adicional suponiendo que el estilo de página highlights
usa las mismas capas que el estilo de página plain.scrheadings
y la nueva capa highlight.bg
:
\documentclass[12pt,ngerman, twoside,open=right]{scrreprt}
\RedeclareSectionCommand[beforeskip=0pt,afterindent=false]{chapter}
\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc}% needed with older TeX distributions
\usepackage{lmodern}
\usepackage{babel}
\usepackage[left=3.8cm,right=2.2cm,top=3cm,bottom=3cm]{geometry}
\usepackage{tikz}% loads xcolor, graphicx etc.
\usepackage[headsepline]{scrlayer-scrpage}
\clearpairofpagestyles
\renewcommand*\pagemark{{\usekomafont{pagenumber}Seite\nobreakspace\thepage}}
\automark[chapter]{chapter}
\ihead{\headmark}
\ohead*{\pagemark}
\DeclareNewLayer[
background,
oddpage,% not on even pages in two-sided documents
head,
hoffset=0pt,
width=\paperwidth,
mode=picture,
contents={\putLL{\tikz{
\fill[shade,left color=blue!0,right color=blue!70]
(0,0)rectangle(\the\layerwidth,\the\layerheight);
}}
}
]{highlights.bg}
\DeclareNewPageStyleByLayers{highlights}{highlights.bg}
\ForEachLayerOfPageStyle{plain.scrheadings}{\AddLayersToPageStyle{highlights}{#1}}% <- add all plain.scrheadings layers to the new page style
\AddToLayerPageStyleOptions{highlights}{oninit=\addtokomafont{pagenumber}{\bfseries\color{white}}\KOMAoptions{headsepline=false}}
\renewcommand\chapterpagestyle{highlights}
\usepackage{blindtext}% only for dummy text
\begin{document}
\chapter{Chapter 1}
Some text.
\blinddocument
\end{document}
Actualizar(con respecto a un comentario a continuación)
Puede usar las opciones addheight
, addhoffset
, addvoffset
, addwidth
, height
, hoffset
y para ajustar la posición voffset
y width
el tamaño de la nueva capa definida con la regla de fondo.
Si desea ampliar verticalmente la regla de fondo del encabezado, puede usar las opciones addvoffset
y addheight
en la definición de capa.
Ejemplo para el segundo MWE anterior:
\DeclareNewLayer[
background,
oddpage,% not on even pages in two-sided documents
head,
addvoffset=2mm,% moves the layer 2mm down
addheight=4mm,% enlarges the height of the layer by 4mm
hoffset=0pt,
width=\paperwidth,
mode=picture,
contents={\putLL{\tikz{
\fill[shade,left color=blue!0,right color=blue!70]
(0,0)rectangle(\the\layerwidth,\the\layerheight);
}}
}
]{highlights.bg}
Si la regla de fondo debe extenderse desde el texto interior hasta el borde exterior del papel, no cambie hoffset
ni ajuste width
:
\DeclareNewLayer[
background,
oddpage,% not on even pages in two-sided documents
head,
addvoffset=2mm,% moves the layer 2mm down
addheight=4mm,% enlarges the height of the layer by 4mm
%hoffset=0pt,% <- removed
width=\paperwidth-1in-\hoffset-\oddsidemargin,% <- changed
mode=picture,
contents={\putLL{\tikz{
\fill[shade,left color=blue!0,right color=blue!70]
(0,0)rectangle(\the\layerwidth,\the\layerheight);
}}
}
]{highlights.bg}
Tenga en cuenta que necesitará una segunda capa si el fondo también se debe utilizar en un documento de dos caras en páginas pares.