Image at begin of chapter
tenllado opened this issue · 11 comments
First of all, this is a very nice package, great job.
I just want to ask you if it is possible to place an image covering a portion of the page (upper quarter for instance) and the chapter title just bellow, as for instance in the official adventure of Dragon of Icespire Peak.
And if I can abuse a little bit, is it also possible to tweak the chapter and section titles font size?
I have experience with latex as a user, but not as a template developer. I looked at the code, but it was not easy for me to follow, that is why I am asking, in the hope that the answer does not require much effort for you. Thank you a lot for your contribution.
You will have to experiment a bit. You might want to modify how the chapter section is rendered with code going in the before option. We use the titlesec package, and you can replace the chapter definition with your own definition (copying the parts you want to keep). This might give an example of what you are looking for. You will probably want to define a \NewDocumentCommand
that will contain the path of the image file. Then you can \RenewDocumentCommand
the image path before each time you call \chapter
to change the image. There are "better" ways to do it, but this would probably be the simplest way to get going. https://tex.stackexchange.com/questions/159978/how-to-add-images-at-the-top-of-the-chapter-title
As for changing the fonts themselves, you will want to take a look at the DndSetFonts function in the class. Each font used in a portion of the class is defined by a font family and a style. You can change these to change the rendering of the corresponding content (chapter, section, table header, table text, etc.).
LaTeX3 code can be tricky to follow. It has a reason to its conventions, but they take a while to learn. The advantage is that certain programming conventions are much easier to use with LaTeX3. Thankfully, you can normally spend most of your time just working with the interface which is in "normal" LaTeX2e.
Thank you a lot for your points. I was playing around and could make it work using this macro:
\newsavebox\DndChapImgBox
\NewDocumentCommand\DndChapter{om}{
\IfNoValueTF{#1}{
\titleformat{\chapter}[display]
{ \DndFontChapter } % format
{} % label
{\wordsep } % sep
{\tikz[remember picture,overlay] \node[xscale=-1,yscale=-1,inner sep=0pt,anchor=north,nearly opaque] at
($(\paperwidth/2 - 2cm,-1em)$)
{\includegraphics[width=\paperwidth]{fig/footerscroll.pdf}};
\DndContour } % before-code
}{
\sbox{\DndChapImgBox}{%
\includegraphics[width=\paperwidth]{#1}%
}
\titleformat{\chapter}[display]
{ \DndFontChapter } % format
{} % label
{.85\ht\DndChapImgBox} % sep
{\tikz[remember picture,overlay] \node[inner sep=0pt,anchor=north] at
($(current page.north)$)
{\usebox\DndChapImgBox};
\tikz[remember picture,overlay] \node[xscale=-1,yscale=-1,inner sep=0pt,anchor=north,nearly opaque] at
($(\paperwidth/2 - 2cm,-1em)$)
{\includegraphics[width=\paperwidth]{fig/footerscroll.pdf}};
\DndContour } % before-code
}
\chapter{#2}
}
This work very fine, It sets the image at the top of the page and the chapter header and the rest of the content of the page is bellow the image.
I tried the same with the section header, to see if I can have a figure at the top of the page at the start of some sections, however this did not work, the text and the section header are rendered on top of the figure. I was not able to figure out why this does not work for sections, It is probably due to some differences in latex in the treatment of chapters and sections. I would appreciate any help on this.
\titleformat
uses [display]
for chapters and a different format for sections, you might need to try [display]
or another format for instances where you have an image before a section. An alternative might be to just show the image inline with \includegraphics
and not use tikz. If I recall correctly, the \tikz[remember picture,overlay]
command causes the image to render and the typesetting image to ignore the space it takes up, which is why you get the text rendering over it. The image's space is preserved for the chapter because of its [display]
style.
Thank you a lot Brian. Again very helpful. I could make it work for sections but following your suggestions I found a better option for sections, when you want tho show an image at the top op the paper without forcing the section to start a new page. Just for reference, in case others are interested, my final code was (using the checkoddpage package):
\begin{figure*}[!t]
\checkoddpage
\vspace*{\the\dimexpr-1in-\voffset-\topmargin-\headheight-\headsep\relax}%
\ifoddpage%
\hspace*{\the\dimexpr-1in-\hoffset-\oddsidemargin\relax}%
\else%
\hspace*{\the\dimexpr-1in-\hoffset-\evensidemargin\relax}%
\fi%
\includegraphics[width=\paperwidth]{path_for_figure}
\end{figure*}
\section{The section title you want}
I still have to check the font sizes but I hope that to be easier (maybe I am being too optimistic :-D).
Thank a lot you for your work and your help.
I am struggling with the use of the \DndSetFonts. I would like to change the size of the section header from \huge to \LARGE and see if that works for me. Looking at the code I figured out that I have to change the font style from:
\linespread{.9} \color{titlered} \huge \scshape \RaggedRight
to
\linespread{.9} \color{titlered} \LARGE \scshape \RaggedRight
But I cannot see how to use the \DndSetFonts macro to achieve this. It is probably a matter of this latex3 syntax. I would appreciate if you could just give me an example of how to use this macro. Thanks a lot.
I am struggling with the use of the \DndSetFonts. I would like to change the size of the section header from \huge to \LARGE and see if that works for me. Looking at the code I figured out that I have to change the font style from:
\linespread{.9} \color{titlered} \huge \scshape \RaggedRight
to
\linespread{.9} \color{titlered} \LARGE \scshape \RaggedRight
But I cannot see how to use the \DndSetFonts macro to achieve this. It is probably a matter of this latex3 syntax. I would appreciate if you could just give me an example of how to use this macro. Thanks a lot.
Setting the font is probably one of the more straightforward parts of the class once you know what to do. The various places where a font is applied to text are in lib/dndfonts.sty, where you can find their default values. Fonts in LaTeX are a combination of family (what we normally call the font) and the style (size, bold, italic, etc.). In your case, you just want to adjust the style of the section. We have it set up where you just need to set the key for the associated style (rather than actually mess with the internals of the class.
\DndSetFonts{section-style = \linespread{.9} \color{titlered} \LARGE \scshape \RaggedRight}
You can place that in the preamble and include more styles to change by separating them with commas.
I had already tried that, but unfortunately I get this error:
! LaTeX3 Error: The key 'dnd/fonts/-NoValue-' is unknown and is being ignored.
For immediate help type H <return>.
...
l.53 \DndSetFonts{
section-style = \linespread{.9} \color{titlered} \LARGE \s...
? H
The module 'dnd/fonts' does not have a key called 'dnd/fonts/-NoValue-'.
Check that you have spelled the key name correctly.
?
Do you know what could be the problem? (I know latex errors are not very informative, so no problem if you cannot help me)
Oops, the definition has the argument being optional \DndSetFonts{o}
so you have to use square brackets. By using curly braces, it is looking to set a mandatory argument and fails to set the keys.
\DndSetFonts[section-style = \linespread{.9} \color{titlered} \LARGE \scshape \RaggedRight]
That is it! Thank you a lot for your help Brian, I really appreciate your effort. I have everything I was looking for! Thank you.
Thank you a lot Brian. Again very helpful. I could make it work for sections but following your suggestions I found a better option for sections, when you want tho show an image at the top op the paper without forcing the section to start a new page. Just for reference, in case others are interested, my final code was (using the checkoddpage package):
\begin{figure*}[!t] \checkoddpage \vspace*{\the\dimexpr-1in-\voffset-\topmargin-\headheight-\headsep\relax}% \ifoddpage% \hspace*{\the\dimexpr-1in-\hoffset-\oddsidemargin\relax}% \else% \hspace*{\the\dimexpr-1in-\hoffset-\evensidemargin\relax}% \fi% \includegraphics[width=\paperwidth]{path_for_figure} \end{figure*} \section{The section title you want}
I still have to check the font sizes but I hope that to be easier (maybe I am being too optimistic :-D).
Thank a lot you for your work and your help.
Hello! I'm trying to add an image as the header of the chapter, but when I compile it stays on another page. Do you have any suggestions to correct it?