Macro returning a length depending on current chapter
Clash Royale CLAN TAG#URR8PPP
I am writing a document using scrbook and I have defined a custom chapter style where I draw a large chapter number using tikz:
renewcommand*chapterformat%
begintikzpicture[remember picture, overlay]
node[anchor=south east, yshift=1.2cm, xshift=textwidth,
inner sep=0, outer sep=0]%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
The chapter number is supposed to align to the right of the text area, but it doesn't because of the whitespace around the number that is part of the character:
The distance to the right border is different for each number. To achieve perfect alignment I would like to adjust the positioning of the chapter number on a per-chapter basis. My idea to achieve this was to define a command that returns a different length depending on the current value of thechapter
, and then use this command to define the xshift
of the chapter number:
newcommand*chapteroffset%
IfEndWiththechapter1textwidth+15mm%
IfEndWiththechapter2textwidth+5mm%
IfEndWiththechapter3textwidth+6mm%
textwidth+0mm%
%
renewcommand*chapterformat%
begintikzpicture[remember picture, overlay]
node[anchor=south east, yshift=1.2cm, xshift=chapteroffset,
inner sep=0, outer sep=0]%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
I've tried multiple different ways to achieve this, but all of them until now have resulted in some kind of endless loop where my document doesn't finish building. I suspect the reason is that I am not using the right way to return a dimension from an if expression.
How can I return a dimension from a macro that changes with the current chapter? Mind that it also needs to work for non-integer numbers in the appendix. Alternatively, how can I achieve the look in the picture in some different way?
This is a current MWE of my status:
documentclass[BCOR=15mm, DIV=8]scrbook
KOMAoptions
headings=twolinechapter,
chapterprefix=false,
numbers=noenddot
usepackagetypearea
usepackage[utf8]inputenc
usepackagekpfonts
usepackage[T1]fontenc
usepackagemicrotype
usepackagelipsum
usepackagetikz
usetikzlibrary
calc,
positioning
tikzset>=latex
usepackagetikzpagenodes
usepackageetoolbox
usepackagexstring
usepackagecalc
definecolorlaccentcolorHTMLd3d3d3
addtokomafontdispositionrmfamily
% Macro that determines the per-chapter offsets.
% If I use this definition, the document will not finish building.
% newcommand*chapteroffset%
% IfEndWiththechapter1textwidth+15mm%
% IfEndWiththechapter2textwidth+5mm%
% IfEndWiththechapter3textwidth+6mm%
% textwidth+0mm%
% %
%
% returning a fixed length from the macro like this works
newcommand*chapteroffsettextwidth+5mm
addtokomafontchapterscshapeLARGE
renewcommand*chapterformat%
begintikzpicture[remember picture, overlay]
node[anchor=south east, yshift=1.2cm, xshift=chapteroffset,
inner sep=0, outer sep=0]%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
renewcommand*chapterheadstartvskipvspace*10cm
begindocument
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
enddocument
tikz-pgf spacing koma-script
add a comment |
I am writing a document using scrbook and I have defined a custom chapter style where I draw a large chapter number using tikz:
renewcommand*chapterformat%
begintikzpicture[remember picture, overlay]
node[anchor=south east, yshift=1.2cm, xshift=textwidth,
inner sep=0, outer sep=0]%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
The chapter number is supposed to align to the right of the text area, but it doesn't because of the whitespace around the number that is part of the character:
The distance to the right border is different for each number. To achieve perfect alignment I would like to adjust the positioning of the chapter number on a per-chapter basis. My idea to achieve this was to define a command that returns a different length depending on the current value of thechapter
, and then use this command to define the xshift
of the chapter number:
newcommand*chapteroffset%
IfEndWiththechapter1textwidth+15mm%
IfEndWiththechapter2textwidth+5mm%
IfEndWiththechapter3textwidth+6mm%
textwidth+0mm%
%
renewcommand*chapterformat%
begintikzpicture[remember picture, overlay]
node[anchor=south east, yshift=1.2cm, xshift=chapteroffset,
inner sep=0, outer sep=0]%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
I've tried multiple different ways to achieve this, but all of them until now have resulted in some kind of endless loop where my document doesn't finish building. I suspect the reason is that I am not using the right way to return a dimension from an if expression.
How can I return a dimension from a macro that changes with the current chapter? Mind that it also needs to work for non-integer numbers in the appendix. Alternatively, how can I achieve the look in the picture in some different way?
This is a current MWE of my status:
documentclass[BCOR=15mm, DIV=8]scrbook
KOMAoptions
headings=twolinechapter,
chapterprefix=false,
numbers=noenddot
usepackagetypearea
usepackage[utf8]inputenc
usepackagekpfonts
usepackage[T1]fontenc
usepackagemicrotype
usepackagelipsum
usepackagetikz
usetikzlibrary
calc,
positioning
tikzset>=latex
usepackagetikzpagenodes
usepackageetoolbox
usepackagexstring
usepackagecalc
definecolorlaccentcolorHTMLd3d3d3
addtokomafontdispositionrmfamily
% Macro that determines the per-chapter offsets.
% If I use this definition, the document will not finish building.
% newcommand*chapteroffset%
% IfEndWiththechapter1textwidth+15mm%
% IfEndWiththechapter2textwidth+5mm%
% IfEndWiththechapter3textwidth+6mm%
% textwidth+0mm%
% %
%
% returning a fixed length from the macro like this works
newcommand*chapteroffsettextwidth+5mm
addtokomafontchapterscshapeLARGE
renewcommand*chapterformat%
begintikzpicture[remember picture, overlay]
node[anchor=south east, yshift=1.2cm, xshift=chapteroffset,
inner sep=0, outer sep=0]%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
renewcommand*chapterheadstartvskipvspace*10cm
begindocument
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
enddocument
tikz-pgf spacing koma-script
1
I'm short in time, so only a note: The commands ofxstring
are not expandable. So you cannot use them in a context, where you need the expanded result of the test. So it maybe it would be better to define asetoffset
-command that sets a lengthchapteroffset
and use that command before you need the value, e.g., before thetikzpicture
. Also:thechapter
does not need to result in a string only (but in your example it should).
– Schweinebacke
Mar 6 at 10:41
add a comment |
I am writing a document using scrbook and I have defined a custom chapter style where I draw a large chapter number using tikz:
renewcommand*chapterformat%
begintikzpicture[remember picture, overlay]
node[anchor=south east, yshift=1.2cm, xshift=textwidth,
inner sep=0, outer sep=0]%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
The chapter number is supposed to align to the right of the text area, but it doesn't because of the whitespace around the number that is part of the character:
The distance to the right border is different for each number. To achieve perfect alignment I would like to adjust the positioning of the chapter number on a per-chapter basis. My idea to achieve this was to define a command that returns a different length depending on the current value of thechapter
, and then use this command to define the xshift
of the chapter number:
newcommand*chapteroffset%
IfEndWiththechapter1textwidth+15mm%
IfEndWiththechapter2textwidth+5mm%
IfEndWiththechapter3textwidth+6mm%
textwidth+0mm%
%
renewcommand*chapterformat%
begintikzpicture[remember picture, overlay]
node[anchor=south east, yshift=1.2cm, xshift=chapteroffset,
inner sep=0, outer sep=0]%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
I've tried multiple different ways to achieve this, but all of them until now have resulted in some kind of endless loop where my document doesn't finish building. I suspect the reason is that I am not using the right way to return a dimension from an if expression.
How can I return a dimension from a macro that changes with the current chapter? Mind that it also needs to work for non-integer numbers in the appendix. Alternatively, how can I achieve the look in the picture in some different way?
This is a current MWE of my status:
documentclass[BCOR=15mm, DIV=8]scrbook
KOMAoptions
headings=twolinechapter,
chapterprefix=false,
numbers=noenddot
usepackagetypearea
usepackage[utf8]inputenc
usepackagekpfonts
usepackage[T1]fontenc
usepackagemicrotype
usepackagelipsum
usepackagetikz
usetikzlibrary
calc,
positioning
tikzset>=latex
usepackagetikzpagenodes
usepackageetoolbox
usepackagexstring
usepackagecalc
definecolorlaccentcolorHTMLd3d3d3
addtokomafontdispositionrmfamily
% Macro that determines the per-chapter offsets.
% If I use this definition, the document will not finish building.
% newcommand*chapteroffset%
% IfEndWiththechapter1textwidth+15mm%
% IfEndWiththechapter2textwidth+5mm%
% IfEndWiththechapter3textwidth+6mm%
% textwidth+0mm%
% %
%
% returning a fixed length from the macro like this works
newcommand*chapteroffsettextwidth+5mm
addtokomafontchapterscshapeLARGE
renewcommand*chapterformat%
begintikzpicture[remember picture, overlay]
node[anchor=south east, yshift=1.2cm, xshift=chapteroffset,
inner sep=0, outer sep=0]%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
renewcommand*chapterheadstartvskipvspace*10cm
begindocument
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
enddocument
tikz-pgf spacing koma-script
I am writing a document using scrbook and I have defined a custom chapter style where I draw a large chapter number using tikz:
renewcommand*chapterformat%
begintikzpicture[remember picture, overlay]
node[anchor=south east, yshift=1.2cm, xshift=textwidth,
inner sep=0, outer sep=0]%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
The chapter number is supposed to align to the right of the text area, but it doesn't because of the whitespace around the number that is part of the character:
The distance to the right border is different for each number. To achieve perfect alignment I would like to adjust the positioning of the chapter number on a per-chapter basis. My idea to achieve this was to define a command that returns a different length depending on the current value of thechapter
, and then use this command to define the xshift
of the chapter number:
newcommand*chapteroffset%
IfEndWiththechapter1textwidth+15mm%
IfEndWiththechapter2textwidth+5mm%
IfEndWiththechapter3textwidth+6mm%
textwidth+0mm%
%
renewcommand*chapterformat%
begintikzpicture[remember picture, overlay]
node[anchor=south east, yshift=1.2cm, xshift=chapteroffset,
inner sep=0, outer sep=0]%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
I've tried multiple different ways to achieve this, but all of them until now have resulted in some kind of endless loop where my document doesn't finish building. I suspect the reason is that I am not using the right way to return a dimension from an if expression.
How can I return a dimension from a macro that changes with the current chapter? Mind that it also needs to work for non-integer numbers in the appendix. Alternatively, how can I achieve the look in the picture in some different way?
This is a current MWE of my status:
documentclass[BCOR=15mm, DIV=8]scrbook
KOMAoptions
headings=twolinechapter,
chapterprefix=false,
numbers=noenddot
usepackagetypearea
usepackage[utf8]inputenc
usepackagekpfonts
usepackage[T1]fontenc
usepackagemicrotype
usepackagelipsum
usepackagetikz
usetikzlibrary
calc,
positioning
tikzset>=latex
usepackagetikzpagenodes
usepackageetoolbox
usepackagexstring
usepackagecalc
definecolorlaccentcolorHTMLd3d3d3
addtokomafontdispositionrmfamily
% Macro that determines the per-chapter offsets.
% If I use this definition, the document will not finish building.
% newcommand*chapteroffset%
% IfEndWiththechapter1textwidth+15mm%
% IfEndWiththechapter2textwidth+5mm%
% IfEndWiththechapter3textwidth+6mm%
% textwidth+0mm%
% %
%
% returning a fixed length from the macro like this works
newcommand*chapteroffsettextwidth+5mm
addtokomafontchapterscshapeLARGE
renewcommand*chapterformat%
begintikzpicture[remember picture, overlay]
node[anchor=south east, yshift=1.2cm, xshift=chapteroffset,
inner sep=0, outer sep=0]%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
renewcommand*chapterheadstartvskipvspace*10cm
begindocument
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
enddocument
tikz-pgf spacing koma-script
tikz-pgf spacing koma-script
edited Mar 6 at 11:33
toster
asked Mar 6 at 10:21
tostertoster
454
454
1
I'm short in time, so only a note: The commands ofxstring
are not expandable. So you cannot use them in a context, where you need the expanded result of the test. So it maybe it would be better to define asetoffset
-command that sets a lengthchapteroffset
and use that command before you need the value, e.g., before thetikzpicture
. Also:thechapter
does not need to result in a string only (but in your example it should).
– Schweinebacke
Mar 6 at 10:41
add a comment |
1
I'm short in time, so only a note: The commands ofxstring
are not expandable. So you cannot use them in a context, where you need the expanded result of the test. So it maybe it would be better to define asetoffset
-command that sets a lengthchapteroffset
and use that command before you need the value, e.g., before thetikzpicture
. Also:thechapter
does not need to result in a string only (but in your example it should).
– Schweinebacke
Mar 6 at 10:41
1
1
I'm short in time, so only a note: The commands of
xstring
are not expandable. So you cannot use them in a context, where you need the expanded result of the test. So it maybe it would be better to define a setoffset
-command that sets a length chapteroffset
and use that command before you need the value, e.g., before the tikzpicture
. Also: thechapter
does not need to result in a string only (but in your example it should).– Schweinebacke
Mar 6 at 10:41
I'm short in time, so only a note: The commands of
xstring
are not expandable. So you cannot use them in a context, where you need the expanded result of the test. So it maybe it would be better to define a setoffset
-command that sets a length chapteroffset
and use that command before you need the value, e.g., before the tikzpicture
. Also: thechapter
does not need to result in a string only (but in your example it should).– Schweinebacke
Mar 6 at 10:41
add a comment |
3 Answers
3
active
oldest
votes
You could just store the shifts in an array, which you could use. Since you are loading tikzpagenodes
, I would also suggest making use of that package.
documentclass[BCOR=15mm, DIV=8]scrbook
KOMAoptions
headings=twolinechapter,
chapterprefix=false,
numbers=noenddot
usepackagetypearea
usepackage[utf8]inputenc
usepackagekpfonts
usepackage[T1]fontenc
usepackagemicrotype
usepackagelipsum
usepackagetikz
usetikzlibrary
calc,
positioning
tikzset>=latex
usepackagetikzpagenodes
usepackageetoolbox
usepackagexstring
usepackagecalc
definecolorlaccentcolorHTMLd3d3d3
addtokomafontdispositionrmfamily
% returning a fixed length from the macro like this works
newcommand*chapteroffsettextwidth+5mm
addtokomafontchapterscshapeLARGE
defchaplengths11mm,5mm,6mm
renewcommand*chapterformat current page text area.east)%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
renewcommand*chapterheadstartvskipvspace*10cm
begindocument
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
enddocument
Thanks, that looks like a workable solution, although I would have to hard code which chapters belong to the appendix. I am not familiar with some of the syntax you used:coordinate (mychapanchor-arabicchapter);
Does this just define a new name for the coordinate per chapter or does the dash imply subtraction?([yshift=1.2cm]mychapanchor-arabicchapter-| current page text area.east)
What does the vertical bar|
mean here? Is this some way of specifying x and y from different coordinates that I don't know yet?
– toster
Mar 6 at 16:00
@toster I am using the array syntax which is explained on p. 999 of the pgfmanual. That is, I store the lengths inchaplengths
by sayingdefchaplengths11mm,5mm,6mm
(note the double) and then access them with
pgfmathsetmacromylengthchaplengths[arabicchapter-1]
(the-1
is because the first element has array index0
).
– marmot
Mar 6 at 16:05
Thanks, but that wasn't the syntax I was unclear on. Please read my comment again.
– toster
Mar 6 at 19:43
@toster Sorry, I indeed didn't read carefully. Yes, this defines new coordinates. Strictly speaking this is not necessary but I find that cleaner. What may, however, be important, is to first set some anchor and then use an overlay picture. (I was actually a bit surprised that it worked so well in your code, but would definitely fix it.) And a very nice discussion on-|
and|-
can be found at tex.stackexchange.com/a/401429/121799. Sorry again!
– marmot
Mar 6 at 19:47
Thanks, I just found this syntax in the pgfmanual. It could have saved me a lot of typing in the past. I used to uselet
expressions to do stuff like this.
– toster
Mar 6 at 19:53
|
show 1 more comment
You can use int_case:nnF
from expl3
:
documentclass[BCOR=15mm, DIV=8]scrbook
KOMAoptions
headings=twolinechapter,
chapterprefix=false,
numbers=noenddot
usepackagetypearea
usepackage[utf8]inputenc
usepackagekpfonts
usepackage[T1]fontenc
usepackagemicrotype
usepackagelipsum,showframe
usepackagetikz
usetikzlibrary
calc,
positioning
tikzset>=latex
usepackagetikzpagenodes
usepackagexparse
definecolorlaccentcolorHTMLd3d3d3
addtokomafontdispositionrmfamily
% Macro that determines the per-chapter offsets.
ExplSyntaxOn
NewExpandableDocumentCommandchapteroffset
textwidth+
int_case:nnF int_mod:nn valuechapter 10
111mm % shift for last digit 1
25mm % shift for last digit 2
36mm % shift for last digit 3
1mm % shift for all other cases
ExplSyntaxOff
addtokomafontchapterscshapeLARGE
renewcommand*chapterformat%
begintikzpicture[remember picture, overlay]
node[anchor=south east, yshift=1.2cm, xshift=chapteroffset,
inner sep=0, outer sep=0]%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
renewcommand*chapterheadstartvskipvspace*10cm
begindocument
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
enddocument
If you want to take care of the appendix add a “variable command”. Perhaps scrbook
has a built-in conditional for testing whether it is in the appendix part. If so, it shouldn't be difficult to use it instead of the home-made ifappendix
.
documentclass[BCOR=15mm, DIV=8]scrbook
KOMAoptions
headings=twolinechapter,
chapterprefix=false,
numbers=noenddot
usepackagetypearea
usepackage[utf8]inputenc
usepackagekpfonts
usepackage[T1]fontenc
usepackagemicrotype
usepackagelipsum,showframe
usepackagetikz
usetikzlibrary
calc,
positioning
tikzset>=latex
usepackagetikzpagenodes
usepackagexparse
definecolorlaccentcolorHTMLd3d3d3
addtokomafontdispositionrmfamily
% Macro that determines the per-chapter offsets.
NewExpandableDocumentCommandchapteroffset
textwidth+
ifappendixoffsetforchapterelseoffsetforappendixfi
newififappendix
ExplSyntaxOn
NewExpandableDocumentCommandoffsetforchapter
int_case:nnF int_mod:nn valuechapter 10
111mm
25mm
36mm
1mm % all other cases
NewExpandableDocumentCommandoffsetforappendix
int_case:nnF valuechapter
111mm % offset for A
25mm % offset for B
36mm % offset for C
1mm % all other cases
ExplSyntaxOff
addtokomafontchapterscshapeLARGE
renewcommand*chapterformat%
begintikzpicture[remember picture, overlay]
node[anchor=south east, yshift=1.2cm, xshift=chapteroffset,
inner sep=0, outer sep=0]%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
renewcommand*chapterheadstartvskipvspace*10cm
begindocument
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1-2]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1-2]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1-2]
appendixappendixtrue
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1-2]
enddocument
add a comment |
Based on marmot and egreg's answers, this is what I ended up using:
newififappendix
defchaplengths11mm,6mm,7mm,2.5mm,7mm,5mm,6mm,7mm,6.5mm
defapplengths4mm,8.5mm,6mm
renewcommand*chapterformat%
begintikzpicture[remember picture]
coordinate (mychapanchor-arabicchapter);
endtikzpicture
begintikzpicture[remember picture, overlay]
pgfmathsetmacromylengthifappendixapplengths[arabicchapter-1]elsechaplengths[arabicchapter-1]fi
node[anchor=south east,xshift=mylength,
inner sep=0, outer sep=0]
at ([yshift=1.2cm]mychapanchor-arabicchapter-
Full MWE:
documentclass[BCOR=15mm, DIV=8]scrbook
KOMAoptions
headings=twolinechapter,
chapterprefix=false,
numbers=noenddot
usepackagetypearea
usepackage[utf8]inputenc
usepackagekpfonts
usepackage[T1]fontenc
usepackagemicrotype
usepackagelipsum
usepackagetikz
usetikzlibrary
calc,
positioning
tikzset>=latex
usepackagetikzpagenodes
usepackageetoolbox
usepackagexstring
usepackagecalc
definecolorlaccentcolorHTMLd3d3d3
addtokomafontdispositionrmfamily
addtokomafontchapterscshapeLARGE
newififappendix
defchaplengths11mm,6mm,7mm,2.5mm,7mm,5mm,6mm,7mm,6.5mm
defapplengths4mm,8.5mm,6mm
renewcommand*chapterformat%
begintikzpicture[remember picture]
coordinate (mychapanchor-arabicchapter);
endtikzpicture
begintikzpicture[remember picture, overlay]
pgfmathsetmacromylengthifappendixapplengths[arabicchapter-1]elsechaplengths[arabicchapter-1]fi
node[anchor=south east,xshift=mylength,
inner sep=0, outer sep=0]
at ([yshift=1.2cm]mychapanchor-arabicchapter-
renewcommand*chapterheadstartvskipvspace*10cm
begindocument
% 1
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 2
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 3
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 4
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 5
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 6
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 7
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 8
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 9
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
appendixappendixtrue
% A
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% B
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% C
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
enddocument
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f478005%2fmacro-returning-a-length-depending-on-current-chapter%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could just store the shifts in an array, which you could use. Since you are loading tikzpagenodes
, I would also suggest making use of that package.
documentclass[BCOR=15mm, DIV=8]scrbook
KOMAoptions
headings=twolinechapter,
chapterprefix=false,
numbers=noenddot
usepackagetypearea
usepackage[utf8]inputenc
usepackagekpfonts
usepackage[T1]fontenc
usepackagemicrotype
usepackagelipsum
usepackagetikz
usetikzlibrary
calc,
positioning
tikzset>=latex
usepackagetikzpagenodes
usepackageetoolbox
usepackagexstring
usepackagecalc
definecolorlaccentcolorHTMLd3d3d3
addtokomafontdispositionrmfamily
% returning a fixed length from the macro like this works
newcommand*chapteroffsettextwidth+5mm
addtokomafontchapterscshapeLARGE
defchaplengths11mm,5mm,6mm
renewcommand*chapterformat current page text area.east)%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
renewcommand*chapterheadstartvskipvspace*10cm
begindocument
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
enddocument
Thanks, that looks like a workable solution, although I would have to hard code which chapters belong to the appendix. I am not familiar with some of the syntax you used:coordinate (mychapanchor-arabicchapter);
Does this just define a new name for the coordinate per chapter or does the dash imply subtraction?([yshift=1.2cm]mychapanchor-arabicchapter-| current page text area.east)
What does the vertical bar|
mean here? Is this some way of specifying x and y from different coordinates that I don't know yet?
– toster
Mar 6 at 16:00
@toster I am using the array syntax which is explained on p. 999 of the pgfmanual. That is, I store the lengths inchaplengths
by sayingdefchaplengths11mm,5mm,6mm
(note the double) and then access them with
pgfmathsetmacromylengthchaplengths[arabicchapter-1]
(the-1
is because the first element has array index0
).
– marmot
Mar 6 at 16:05
Thanks, but that wasn't the syntax I was unclear on. Please read my comment again.
– toster
Mar 6 at 19:43
@toster Sorry, I indeed didn't read carefully. Yes, this defines new coordinates. Strictly speaking this is not necessary but I find that cleaner. What may, however, be important, is to first set some anchor and then use an overlay picture. (I was actually a bit surprised that it worked so well in your code, but would definitely fix it.) And a very nice discussion on-|
and|-
can be found at tex.stackexchange.com/a/401429/121799. Sorry again!
– marmot
Mar 6 at 19:47
Thanks, I just found this syntax in the pgfmanual. It could have saved me a lot of typing in the past. I used to uselet
expressions to do stuff like this.
– toster
Mar 6 at 19:53
|
show 1 more comment
You could just store the shifts in an array, which you could use. Since you are loading tikzpagenodes
, I would also suggest making use of that package.
documentclass[BCOR=15mm, DIV=8]scrbook
KOMAoptions
headings=twolinechapter,
chapterprefix=false,
numbers=noenddot
usepackagetypearea
usepackage[utf8]inputenc
usepackagekpfonts
usepackage[T1]fontenc
usepackagemicrotype
usepackagelipsum
usepackagetikz
usetikzlibrary
calc,
positioning
tikzset>=latex
usepackagetikzpagenodes
usepackageetoolbox
usepackagexstring
usepackagecalc
definecolorlaccentcolorHTMLd3d3d3
addtokomafontdispositionrmfamily
% returning a fixed length from the macro like this works
newcommand*chapteroffsettextwidth+5mm
addtokomafontchapterscshapeLARGE
defchaplengths11mm,5mm,6mm
renewcommand*chapterformat current page text area.east)%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
renewcommand*chapterheadstartvskipvspace*10cm
begindocument
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
enddocument
Thanks, that looks like a workable solution, although I would have to hard code which chapters belong to the appendix. I am not familiar with some of the syntax you used:coordinate (mychapanchor-arabicchapter);
Does this just define a new name for the coordinate per chapter or does the dash imply subtraction?([yshift=1.2cm]mychapanchor-arabicchapter-| current page text area.east)
What does the vertical bar|
mean here? Is this some way of specifying x and y from different coordinates that I don't know yet?
– toster
Mar 6 at 16:00
@toster I am using the array syntax which is explained on p. 999 of the pgfmanual. That is, I store the lengths inchaplengths
by sayingdefchaplengths11mm,5mm,6mm
(note the double) and then access them with
pgfmathsetmacromylengthchaplengths[arabicchapter-1]
(the-1
is because the first element has array index0
).
– marmot
Mar 6 at 16:05
Thanks, but that wasn't the syntax I was unclear on. Please read my comment again.
– toster
Mar 6 at 19:43
@toster Sorry, I indeed didn't read carefully. Yes, this defines new coordinates. Strictly speaking this is not necessary but I find that cleaner. What may, however, be important, is to first set some anchor and then use an overlay picture. (I was actually a bit surprised that it worked so well in your code, but would definitely fix it.) And a very nice discussion on-|
and|-
can be found at tex.stackexchange.com/a/401429/121799. Sorry again!
– marmot
Mar 6 at 19:47
Thanks, I just found this syntax in the pgfmanual. It could have saved me a lot of typing in the past. I used to uselet
expressions to do stuff like this.
– toster
Mar 6 at 19:53
|
show 1 more comment
You could just store the shifts in an array, which you could use. Since you are loading tikzpagenodes
, I would also suggest making use of that package.
documentclass[BCOR=15mm, DIV=8]scrbook
KOMAoptions
headings=twolinechapter,
chapterprefix=false,
numbers=noenddot
usepackagetypearea
usepackage[utf8]inputenc
usepackagekpfonts
usepackage[T1]fontenc
usepackagemicrotype
usepackagelipsum
usepackagetikz
usetikzlibrary
calc,
positioning
tikzset>=latex
usepackagetikzpagenodes
usepackageetoolbox
usepackagexstring
usepackagecalc
definecolorlaccentcolorHTMLd3d3d3
addtokomafontdispositionrmfamily
% returning a fixed length from the macro like this works
newcommand*chapteroffsettextwidth+5mm
addtokomafontchapterscshapeLARGE
defchaplengths11mm,5mm,6mm
renewcommand*chapterformat current page text area.east)%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
renewcommand*chapterheadstartvskipvspace*10cm
begindocument
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
enddocument
You could just store the shifts in an array, which you could use. Since you are loading tikzpagenodes
, I would also suggest making use of that package.
documentclass[BCOR=15mm, DIV=8]scrbook
KOMAoptions
headings=twolinechapter,
chapterprefix=false,
numbers=noenddot
usepackagetypearea
usepackage[utf8]inputenc
usepackagekpfonts
usepackage[T1]fontenc
usepackagemicrotype
usepackagelipsum
usepackagetikz
usetikzlibrary
calc,
positioning
tikzset>=latex
usepackagetikzpagenodes
usepackageetoolbox
usepackagexstring
usepackagecalc
definecolorlaccentcolorHTMLd3d3d3
addtokomafontdispositionrmfamily
% returning a fixed length from the macro like this works
newcommand*chapteroffsettextwidth+5mm
addtokomafontchapterscshapeLARGE
defchaplengths11mm,5mm,6mm
renewcommand*chapterformat current page text area.east)%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
renewcommand*chapterheadstartvskipvspace*10cm
begindocument
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
enddocument
answered Mar 6 at 15:31
marmotmarmot
114k5145276
114k5145276
Thanks, that looks like a workable solution, although I would have to hard code which chapters belong to the appendix. I am not familiar with some of the syntax you used:coordinate (mychapanchor-arabicchapter);
Does this just define a new name for the coordinate per chapter or does the dash imply subtraction?([yshift=1.2cm]mychapanchor-arabicchapter-| current page text area.east)
What does the vertical bar|
mean here? Is this some way of specifying x and y from different coordinates that I don't know yet?
– toster
Mar 6 at 16:00
@toster I am using the array syntax which is explained on p. 999 of the pgfmanual. That is, I store the lengths inchaplengths
by sayingdefchaplengths11mm,5mm,6mm
(note the double) and then access them with
pgfmathsetmacromylengthchaplengths[arabicchapter-1]
(the-1
is because the first element has array index0
).
– marmot
Mar 6 at 16:05
Thanks, but that wasn't the syntax I was unclear on. Please read my comment again.
– toster
Mar 6 at 19:43
@toster Sorry, I indeed didn't read carefully. Yes, this defines new coordinates. Strictly speaking this is not necessary but I find that cleaner. What may, however, be important, is to first set some anchor and then use an overlay picture. (I was actually a bit surprised that it worked so well in your code, but would definitely fix it.) And a very nice discussion on-|
and|-
can be found at tex.stackexchange.com/a/401429/121799. Sorry again!
– marmot
Mar 6 at 19:47
Thanks, I just found this syntax in the pgfmanual. It could have saved me a lot of typing in the past. I used to uselet
expressions to do stuff like this.
– toster
Mar 6 at 19:53
|
show 1 more comment
Thanks, that looks like a workable solution, although I would have to hard code which chapters belong to the appendix. I am not familiar with some of the syntax you used:coordinate (mychapanchor-arabicchapter);
Does this just define a new name for the coordinate per chapter or does the dash imply subtraction?([yshift=1.2cm]mychapanchor-arabicchapter-| current page text area.east)
What does the vertical bar|
mean here? Is this some way of specifying x and y from different coordinates that I don't know yet?
– toster
Mar 6 at 16:00
@toster I am using the array syntax which is explained on p. 999 of the pgfmanual. That is, I store the lengths inchaplengths
by sayingdefchaplengths11mm,5mm,6mm
(note the double) and then access them with
pgfmathsetmacromylengthchaplengths[arabicchapter-1]
(the-1
is because the first element has array index0
).
– marmot
Mar 6 at 16:05
Thanks, but that wasn't the syntax I was unclear on. Please read my comment again.
– toster
Mar 6 at 19:43
@toster Sorry, I indeed didn't read carefully. Yes, this defines new coordinates. Strictly speaking this is not necessary but I find that cleaner. What may, however, be important, is to first set some anchor and then use an overlay picture. (I was actually a bit surprised that it worked so well in your code, but would definitely fix it.) And a very nice discussion on-|
and|-
can be found at tex.stackexchange.com/a/401429/121799. Sorry again!
– marmot
Mar 6 at 19:47
Thanks, I just found this syntax in the pgfmanual. It could have saved me a lot of typing in the past. I used to uselet
expressions to do stuff like this.
– toster
Mar 6 at 19:53
Thanks, that looks like a workable solution, although I would have to hard code which chapters belong to the appendix. I am not familiar with some of the syntax you used:
coordinate (mychapanchor-arabicchapter);
Does this just define a new name for the coordinate per chapter or does the dash imply subtraction? ([yshift=1.2cm]mychapanchor-arabicchapter-| current page text area.east)
What does the vertical bar |
mean here? Is this some way of specifying x and y from different coordinates that I don't know yet?– toster
Mar 6 at 16:00
Thanks, that looks like a workable solution, although I would have to hard code which chapters belong to the appendix. I am not familiar with some of the syntax you used:
coordinate (mychapanchor-arabicchapter);
Does this just define a new name for the coordinate per chapter or does the dash imply subtraction? ([yshift=1.2cm]mychapanchor-arabicchapter-| current page text area.east)
What does the vertical bar |
mean here? Is this some way of specifying x and y from different coordinates that I don't know yet?– toster
Mar 6 at 16:00
@toster I am using the array syntax which is explained on p. 999 of the pgfmanual. That is, I store the lengths in
chaplengths
by saying defchaplengths11mm,5mm,6mm
(note the double
) and then access them with pgfmathsetmacromylengthchaplengths[arabicchapter-1]
(the -1
is because the first element has array index 0
).– marmot
Mar 6 at 16:05
@toster I am using the array syntax which is explained on p. 999 of the pgfmanual. That is, I store the lengths in
chaplengths
by saying defchaplengths11mm,5mm,6mm
(note the double
) and then access them with pgfmathsetmacromylengthchaplengths[arabicchapter-1]
(the -1
is because the first element has array index 0
).– marmot
Mar 6 at 16:05
Thanks, but that wasn't the syntax I was unclear on. Please read my comment again.
– toster
Mar 6 at 19:43
Thanks, but that wasn't the syntax I was unclear on. Please read my comment again.
– toster
Mar 6 at 19:43
@toster Sorry, I indeed didn't read carefully. Yes, this defines new coordinates. Strictly speaking this is not necessary but I find that cleaner. What may, however, be important, is to first set some anchor and then use an overlay picture. (I was actually a bit surprised that it worked so well in your code, but would definitely fix it.) And a very nice discussion on
-|
and |-
can be found at tex.stackexchange.com/a/401429/121799. Sorry again!– marmot
Mar 6 at 19:47
@toster Sorry, I indeed didn't read carefully. Yes, this defines new coordinates. Strictly speaking this is not necessary but I find that cleaner. What may, however, be important, is to first set some anchor and then use an overlay picture. (I was actually a bit surprised that it worked so well in your code, but would definitely fix it.) And a very nice discussion on
-|
and |-
can be found at tex.stackexchange.com/a/401429/121799. Sorry again!– marmot
Mar 6 at 19:47
Thanks, I just found this syntax in the pgfmanual. It could have saved me a lot of typing in the past. I used to use
let
expressions to do stuff like this.– toster
Mar 6 at 19:53
Thanks, I just found this syntax in the pgfmanual. It could have saved me a lot of typing in the past. I used to use
let
expressions to do stuff like this.– toster
Mar 6 at 19:53
|
show 1 more comment
You can use int_case:nnF
from expl3
:
documentclass[BCOR=15mm, DIV=8]scrbook
KOMAoptions
headings=twolinechapter,
chapterprefix=false,
numbers=noenddot
usepackagetypearea
usepackage[utf8]inputenc
usepackagekpfonts
usepackage[T1]fontenc
usepackagemicrotype
usepackagelipsum,showframe
usepackagetikz
usetikzlibrary
calc,
positioning
tikzset>=latex
usepackagetikzpagenodes
usepackagexparse
definecolorlaccentcolorHTMLd3d3d3
addtokomafontdispositionrmfamily
% Macro that determines the per-chapter offsets.
ExplSyntaxOn
NewExpandableDocumentCommandchapteroffset
textwidth+
int_case:nnF int_mod:nn valuechapter 10
111mm % shift for last digit 1
25mm % shift for last digit 2
36mm % shift for last digit 3
1mm % shift for all other cases
ExplSyntaxOff
addtokomafontchapterscshapeLARGE
renewcommand*chapterformat%
begintikzpicture[remember picture, overlay]
node[anchor=south east, yshift=1.2cm, xshift=chapteroffset,
inner sep=0, outer sep=0]%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
renewcommand*chapterheadstartvskipvspace*10cm
begindocument
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
enddocument
If you want to take care of the appendix add a “variable command”. Perhaps scrbook
has a built-in conditional for testing whether it is in the appendix part. If so, it shouldn't be difficult to use it instead of the home-made ifappendix
.
documentclass[BCOR=15mm, DIV=8]scrbook
KOMAoptions
headings=twolinechapter,
chapterprefix=false,
numbers=noenddot
usepackagetypearea
usepackage[utf8]inputenc
usepackagekpfonts
usepackage[T1]fontenc
usepackagemicrotype
usepackagelipsum,showframe
usepackagetikz
usetikzlibrary
calc,
positioning
tikzset>=latex
usepackagetikzpagenodes
usepackagexparse
definecolorlaccentcolorHTMLd3d3d3
addtokomafontdispositionrmfamily
% Macro that determines the per-chapter offsets.
NewExpandableDocumentCommandchapteroffset
textwidth+
ifappendixoffsetforchapterelseoffsetforappendixfi
newififappendix
ExplSyntaxOn
NewExpandableDocumentCommandoffsetforchapter
int_case:nnF int_mod:nn valuechapter 10
111mm
25mm
36mm
1mm % all other cases
NewExpandableDocumentCommandoffsetforappendix
int_case:nnF valuechapter
111mm % offset for A
25mm % offset for B
36mm % offset for C
1mm % all other cases
ExplSyntaxOff
addtokomafontchapterscshapeLARGE
renewcommand*chapterformat%
begintikzpicture[remember picture, overlay]
node[anchor=south east, yshift=1.2cm, xshift=chapteroffset,
inner sep=0, outer sep=0]%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
renewcommand*chapterheadstartvskipvspace*10cm
begindocument
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1-2]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1-2]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1-2]
appendixappendixtrue
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1-2]
enddocument
add a comment |
You can use int_case:nnF
from expl3
:
documentclass[BCOR=15mm, DIV=8]scrbook
KOMAoptions
headings=twolinechapter,
chapterprefix=false,
numbers=noenddot
usepackagetypearea
usepackage[utf8]inputenc
usepackagekpfonts
usepackage[T1]fontenc
usepackagemicrotype
usepackagelipsum,showframe
usepackagetikz
usetikzlibrary
calc,
positioning
tikzset>=latex
usepackagetikzpagenodes
usepackagexparse
definecolorlaccentcolorHTMLd3d3d3
addtokomafontdispositionrmfamily
% Macro that determines the per-chapter offsets.
ExplSyntaxOn
NewExpandableDocumentCommandchapteroffset
textwidth+
int_case:nnF int_mod:nn valuechapter 10
111mm % shift for last digit 1
25mm % shift for last digit 2
36mm % shift for last digit 3
1mm % shift for all other cases
ExplSyntaxOff
addtokomafontchapterscshapeLARGE
renewcommand*chapterformat%
begintikzpicture[remember picture, overlay]
node[anchor=south east, yshift=1.2cm, xshift=chapteroffset,
inner sep=0, outer sep=0]%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
renewcommand*chapterheadstartvskipvspace*10cm
begindocument
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
enddocument
If you want to take care of the appendix add a “variable command”. Perhaps scrbook
has a built-in conditional for testing whether it is in the appendix part. If so, it shouldn't be difficult to use it instead of the home-made ifappendix
.
documentclass[BCOR=15mm, DIV=8]scrbook
KOMAoptions
headings=twolinechapter,
chapterprefix=false,
numbers=noenddot
usepackagetypearea
usepackage[utf8]inputenc
usepackagekpfonts
usepackage[T1]fontenc
usepackagemicrotype
usepackagelipsum,showframe
usepackagetikz
usetikzlibrary
calc,
positioning
tikzset>=latex
usepackagetikzpagenodes
usepackagexparse
definecolorlaccentcolorHTMLd3d3d3
addtokomafontdispositionrmfamily
% Macro that determines the per-chapter offsets.
NewExpandableDocumentCommandchapteroffset
textwidth+
ifappendixoffsetforchapterelseoffsetforappendixfi
newififappendix
ExplSyntaxOn
NewExpandableDocumentCommandoffsetforchapter
int_case:nnF int_mod:nn valuechapter 10
111mm
25mm
36mm
1mm % all other cases
NewExpandableDocumentCommandoffsetforappendix
int_case:nnF valuechapter
111mm % offset for A
25mm % offset for B
36mm % offset for C
1mm % all other cases
ExplSyntaxOff
addtokomafontchapterscshapeLARGE
renewcommand*chapterformat%
begintikzpicture[remember picture, overlay]
node[anchor=south east, yshift=1.2cm, xshift=chapteroffset,
inner sep=0, outer sep=0]%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
renewcommand*chapterheadstartvskipvspace*10cm
begindocument
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1-2]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1-2]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1-2]
appendixappendixtrue
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1-2]
enddocument
add a comment |
You can use int_case:nnF
from expl3
:
documentclass[BCOR=15mm, DIV=8]scrbook
KOMAoptions
headings=twolinechapter,
chapterprefix=false,
numbers=noenddot
usepackagetypearea
usepackage[utf8]inputenc
usepackagekpfonts
usepackage[T1]fontenc
usepackagemicrotype
usepackagelipsum,showframe
usepackagetikz
usetikzlibrary
calc,
positioning
tikzset>=latex
usepackagetikzpagenodes
usepackagexparse
definecolorlaccentcolorHTMLd3d3d3
addtokomafontdispositionrmfamily
% Macro that determines the per-chapter offsets.
ExplSyntaxOn
NewExpandableDocumentCommandchapteroffset
textwidth+
int_case:nnF int_mod:nn valuechapter 10
111mm % shift for last digit 1
25mm % shift for last digit 2
36mm % shift for last digit 3
1mm % shift for all other cases
ExplSyntaxOff
addtokomafontchapterscshapeLARGE
renewcommand*chapterformat%
begintikzpicture[remember picture, overlay]
node[anchor=south east, yshift=1.2cm, xshift=chapteroffset,
inner sep=0, outer sep=0]%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
renewcommand*chapterheadstartvskipvspace*10cm
begindocument
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
enddocument
If you want to take care of the appendix add a “variable command”. Perhaps scrbook
has a built-in conditional for testing whether it is in the appendix part. If so, it shouldn't be difficult to use it instead of the home-made ifappendix
.
documentclass[BCOR=15mm, DIV=8]scrbook
KOMAoptions
headings=twolinechapter,
chapterprefix=false,
numbers=noenddot
usepackagetypearea
usepackage[utf8]inputenc
usepackagekpfonts
usepackage[T1]fontenc
usepackagemicrotype
usepackagelipsum,showframe
usepackagetikz
usetikzlibrary
calc,
positioning
tikzset>=latex
usepackagetikzpagenodes
usepackagexparse
definecolorlaccentcolorHTMLd3d3d3
addtokomafontdispositionrmfamily
% Macro that determines the per-chapter offsets.
NewExpandableDocumentCommandchapteroffset
textwidth+
ifappendixoffsetforchapterelseoffsetforappendixfi
newififappendix
ExplSyntaxOn
NewExpandableDocumentCommandoffsetforchapter
int_case:nnF int_mod:nn valuechapter 10
111mm
25mm
36mm
1mm % all other cases
NewExpandableDocumentCommandoffsetforappendix
int_case:nnF valuechapter
111mm % offset for A
25mm % offset for B
36mm % offset for C
1mm % all other cases
ExplSyntaxOff
addtokomafontchapterscshapeLARGE
renewcommand*chapterformat%
begintikzpicture[remember picture, overlay]
node[anchor=south east, yshift=1.2cm, xshift=chapteroffset,
inner sep=0, outer sep=0]%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
renewcommand*chapterheadstartvskipvspace*10cm
begindocument
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1-2]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1-2]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1-2]
appendixappendixtrue
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1-2]
enddocument
You can use int_case:nnF
from expl3
:
documentclass[BCOR=15mm, DIV=8]scrbook
KOMAoptions
headings=twolinechapter,
chapterprefix=false,
numbers=noenddot
usepackagetypearea
usepackage[utf8]inputenc
usepackagekpfonts
usepackage[T1]fontenc
usepackagemicrotype
usepackagelipsum,showframe
usepackagetikz
usetikzlibrary
calc,
positioning
tikzset>=latex
usepackagetikzpagenodes
usepackagexparse
definecolorlaccentcolorHTMLd3d3d3
addtokomafontdispositionrmfamily
% Macro that determines the per-chapter offsets.
ExplSyntaxOn
NewExpandableDocumentCommandchapteroffset
textwidth+
int_case:nnF int_mod:nn valuechapter 10
111mm % shift for last digit 1
25mm % shift for last digit 2
36mm % shift for last digit 3
1mm % shift for all other cases
ExplSyntaxOff
addtokomafontchapterscshapeLARGE
renewcommand*chapterformat%
begintikzpicture[remember picture, overlay]
node[anchor=south east, yshift=1.2cm, xshift=chapteroffset,
inner sep=0, outer sep=0]%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
renewcommand*chapterheadstartvskipvspace*10cm
begindocument
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
enddocument
If you want to take care of the appendix add a “variable command”. Perhaps scrbook
has a built-in conditional for testing whether it is in the appendix part. If so, it shouldn't be difficult to use it instead of the home-made ifappendix
.
documentclass[BCOR=15mm, DIV=8]scrbook
KOMAoptions
headings=twolinechapter,
chapterprefix=false,
numbers=noenddot
usepackagetypearea
usepackage[utf8]inputenc
usepackagekpfonts
usepackage[T1]fontenc
usepackagemicrotype
usepackagelipsum,showframe
usepackagetikz
usetikzlibrary
calc,
positioning
tikzset>=latex
usepackagetikzpagenodes
usepackagexparse
definecolorlaccentcolorHTMLd3d3d3
addtokomafontdispositionrmfamily
% Macro that determines the per-chapter offsets.
NewExpandableDocumentCommandchapteroffset
textwidth+
ifappendixoffsetforchapterelseoffsetforappendixfi
newififappendix
ExplSyntaxOn
NewExpandableDocumentCommandoffsetforchapter
int_case:nnF int_mod:nn valuechapter 10
111mm
25mm
36mm
1mm % all other cases
NewExpandableDocumentCommandoffsetforappendix
int_case:nnF valuechapter
111mm % offset for A
25mm % offset for B
36mm % offset for C
1mm % all other cases
ExplSyntaxOff
addtokomafontchapterscshapeLARGE
renewcommand*chapterformat%
begintikzpicture[remember picture, overlay]
node[anchor=south east, yshift=1.2cm, xshift=chapteroffset,
inner sep=0, outer sep=0]%
fontsize10cm10cmselectfont%
textcolorlaccentcolorthechapter%
;
% alignment line
draw[thin] (current page text area.north east)
-- (current page text area.south east);
endtikzpicture%
renewcommand*chapterheadstartvskipvspace*10cm
begindocument
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1-2]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1-2]
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1-2]
appendixappendixtrue
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1-2]
enddocument
edited Mar 6 at 11:58
answered Mar 6 at 10:42
egregegreg
731k8919303250
731k8919303250
add a comment |
add a comment |
Based on marmot and egreg's answers, this is what I ended up using:
newififappendix
defchaplengths11mm,6mm,7mm,2.5mm,7mm,5mm,6mm,7mm,6.5mm
defapplengths4mm,8.5mm,6mm
renewcommand*chapterformat%
begintikzpicture[remember picture]
coordinate (mychapanchor-arabicchapter);
endtikzpicture
begintikzpicture[remember picture, overlay]
pgfmathsetmacromylengthifappendixapplengths[arabicchapter-1]elsechaplengths[arabicchapter-1]fi
node[anchor=south east,xshift=mylength,
inner sep=0, outer sep=0]
at ([yshift=1.2cm]mychapanchor-arabicchapter-
Full MWE:
documentclass[BCOR=15mm, DIV=8]scrbook
KOMAoptions
headings=twolinechapter,
chapterprefix=false,
numbers=noenddot
usepackagetypearea
usepackage[utf8]inputenc
usepackagekpfonts
usepackage[T1]fontenc
usepackagemicrotype
usepackagelipsum
usepackagetikz
usetikzlibrary
calc,
positioning
tikzset>=latex
usepackagetikzpagenodes
usepackageetoolbox
usepackagexstring
usepackagecalc
definecolorlaccentcolorHTMLd3d3d3
addtokomafontdispositionrmfamily
addtokomafontchapterscshapeLARGE
newififappendix
defchaplengths11mm,6mm,7mm,2.5mm,7mm,5mm,6mm,7mm,6.5mm
defapplengths4mm,8.5mm,6mm
renewcommand*chapterformat%
begintikzpicture[remember picture]
coordinate (mychapanchor-arabicchapter);
endtikzpicture
begintikzpicture[remember picture, overlay]
pgfmathsetmacromylengthifappendixapplengths[arabicchapter-1]elsechaplengths[arabicchapter-1]fi
node[anchor=south east,xshift=mylength,
inner sep=0, outer sep=0]
at ([yshift=1.2cm]mychapanchor-arabicchapter-
renewcommand*chapterheadstartvskipvspace*10cm
begindocument
% 1
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 2
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 3
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 4
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 5
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 6
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 7
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 8
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 9
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
appendixappendixtrue
% A
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% B
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% C
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
enddocument
add a comment |
Based on marmot and egreg's answers, this is what I ended up using:
newififappendix
defchaplengths11mm,6mm,7mm,2.5mm,7mm,5mm,6mm,7mm,6.5mm
defapplengths4mm,8.5mm,6mm
renewcommand*chapterformat%
begintikzpicture[remember picture]
coordinate (mychapanchor-arabicchapter);
endtikzpicture
begintikzpicture[remember picture, overlay]
pgfmathsetmacromylengthifappendixapplengths[arabicchapter-1]elsechaplengths[arabicchapter-1]fi
node[anchor=south east,xshift=mylength,
inner sep=0, outer sep=0]
at ([yshift=1.2cm]mychapanchor-arabicchapter-
Full MWE:
documentclass[BCOR=15mm, DIV=8]scrbook
KOMAoptions
headings=twolinechapter,
chapterprefix=false,
numbers=noenddot
usepackagetypearea
usepackage[utf8]inputenc
usepackagekpfonts
usepackage[T1]fontenc
usepackagemicrotype
usepackagelipsum
usepackagetikz
usetikzlibrary
calc,
positioning
tikzset>=latex
usepackagetikzpagenodes
usepackageetoolbox
usepackagexstring
usepackagecalc
definecolorlaccentcolorHTMLd3d3d3
addtokomafontdispositionrmfamily
addtokomafontchapterscshapeLARGE
newififappendix
defchaplengths11mm,6mm,7mm,2.5mm,7mm,5mm,6mm,7mm,6.5mm
defapplengths4mm,8.5mm,6mm
renewcommand*chapterformat%
begintikzpicture[remember picture]
coordinate (mychapanchor-arabicchapter);
endtikzpicture
begintikzpicture[remember picture, overlay]
pgfmathsetmacromylengthifappendixapplengths[arabicchapter-1]elsechaplengths[arabicchapter-1]fi
node[anchor=south east,xshift=mylength,
inner sep=0, outer sep=0]
at ([yshift=1.2cm]mychapanchor-arabicchapter-
renewcommand*chapterheadstartvskipvspace*10cm
begindocument
% 1
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 2
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 3
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 4
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 5
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 6
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 7
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 8
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 9
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
appendixappendixtrue
% A
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% B
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% C
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
enddocument
add a comment |
Based on marmot and egreg's answers, this is what I ended up using:
newififappendix
defchaplengths11mm,6mm,7mm,2.5mm,7mm,5mm,6mm,7mm,6.5mm
defapplengths4mm,8.5mm,6mm
renewcommand*chapterformat%
begintikzpicture[remember picture]
coordinate (mychapanchor-arabicchapter);
endtikzpicture
begintikzpicture[remember picture, overlay]
pgfmathsetmacromylengthifappendixapplengths[arabicchapter-1]elsechaplengths[arabicchapter-1]fi
node[anchor=south east,xshift=mylength,
inner sep=0, outer sep=0]
at ([yshift=1.2cm]mychapanchor-arabicchapter-
Full MWE:
documentclass[BCOR=15mm, DIV=8]scrbook
KOMAoptions
headings=twolinechapter,
chapterprefix=false,
numbers=noenddot
usepackagetypearea
usepackage[utf8]inputenc
usepackagekpfonts
usepackage[T1]fontenc
usepackagemicrotype
usepackagelipsum
usepackagetikz
usetikzlibrary
calc,
positioning
tikzset>=latex
usepackagetikzpagenodes
usepackageetoolbox
usepackagexstring
usepackagecalc
definecolorlaccentcolorHTMLd3d3d3
addtokomafontdispositionrmfamily
addtokomafontchapterscshapeLARGE
newififappendix
defchaplengths11mm,6mm,7mm,2.5mm,7mm,5mm,6mm,7mm,6.5mm
defapplengths4mm,8.5mm,6mm
renewcommand*chapterformat%
begintikzpicture[remember picture]
coordinate (mychapanchor-arabicchapter);
endtikzpicture
begintikzpicture[remember picture, overlay]
pgfmathsetmacromylengthifappendixapplengths[arabicchapter-1]elsechaplengths[arabicchapter-1]fi
node[anchor=south east,xshift=mylength,
inner sep=0, outer sep=0]
at ([yshift=1.2cm]mychapanchor-arabicchapter-
renewcommand*chapterheadstartvskipvspace*10cm
begindocument
% 1
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 2
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 3
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 4
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 5
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 6
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 7
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 8
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 9
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
appendixappendixtrue
% A
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% B
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% C
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
enddocument
Based on marmot and egreg's answers, this is what I ended up using:
newififappendix
defchaplengths11mm,6mm,7mm,2.5mm,7mm,5mm,6mm,7mm,6.5mm
defapplengths4mm,8.5mm,6mm
renewcommand*chapterformat%
begintikzpicture[remember picture]
coordinate (mychapanchor-arabicchapter);
endtikzpicture
begintikzpicture[remember picture, overlay]
pgfmathsetmacromylengthifappendixapplengths[arabicchapter-1]elsechaplengths[arabicchapter-1]fi
node[anchor=south east,xshift=mylength,
inner sep=0, outer sep=0]
at ([yshift=1.2cm]mychapanchor-arabicchapter-
Full MWE:
documentclass[BCOR=15mm, DIV=8]scrbook
KOMAoptions
headings=twolinechapter,
chapterprefix=false,
numbers=noenddot
usepackagetypearea
usepackage[utf8]inputenc
usepackagekpfonts
usepackage[T1]fontenc
usepackagemicrotype
usepackagelipsum
usepackagetikz
usetikzlibrary
calc,
positioning
tikzset>=latex
usepackagetikzpagenodes
usepackageetoolbox
usepackagexstring
usepackagecalc
definecolorlaccentcolorHTMLd3d3d3
addtokomafontdispositionrmfamily
addtokomafontchapterscshapeLARGE
newififappendix
defchaplengths11mm,6mm,7mm,2.5mm,7mm,5mm,6mm,7mm,6.5mm
defapplengths4mm,8.5mm,6mm
renewcommand*chapterformat%
begintikzpicture[remember picture]
coordinate (mychapanchor-arabicchapter);
endtikzpicture
begintikzpicture[remember picture, overlay]
pgfmathsetmacromylengthifappendixapplengths[arabicchapter-1]elsechaplengths[arabicchapter-1]fi
node[anchor=south east,xshift=mylength,
inner sep=0, outer sep=0]
at ([yshift=1.2cm]mychapanchor-arabicchapter-
renewcommand*chapterheadstartvskipvspace*10cm
begindocument
% 1
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 2
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 3
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 4
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 5
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 6
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 7
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 8
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% 9
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
appendixappendixtrue
% A
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% B
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
% C
chapterA Fancy Chapter Name to Test the Formatting
lipsum[1]
enddocument
answered Mar 6 at 20:32
tostertoster
454
454
add a comment |
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f478005%2fmacro-returning-a-length-depending-on-current-chapter%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I'm short in time, so only a note: The commands of
xstring
are not expandable. So you cannot use them in a context, where you need the expanded result of the test. So it maybe it would be better to define asetoffset
-command that sets a lengthchapteroffset
and use that command before you need the value, e.g., before thetikzpicture
. Also:thechapter
does not need to result in a string only (but in your example it should).– Schweinebacke
Mar 6 at 10:41