Difference between revisions of "KOMA-scrartcl Type Area"

From Wiki
Jump to navigation Jump to search
 
(→‎LaTeX: corrected reference to typearea package)
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
< [[From LaTeX to ConTeXt]]
+
< [[From LaTeX to ConTeXt]] >
  
LaTeX:
+
== LaTeX ==
<pre>
+
 
 +
The <tt>typearea</tt> style from the KOMA package (used per default in the KOMA classes) does some fairly sophisticated calculations to determine an optimal page layout, with the text width set in terms of average characters-per-line, and the text height and location set to provide pleasing proportions based on that and the paper proportions.  A sample document (with a framebox to show the text area) is simply:
 +
 
 +
<texcode>
 +
\documentclass{article}
 +
\usepackage[DIVcalc,twoside]{typearea}
 +
\begin{document}
 +
\noindent\framebox{\rule{0pt}{\textheight}\rule{\textwidth}{0pt}}
 +
\end{document}
 +
</texcode>
 +
 
 +
or
 +
 
 +
<texcode>
 
\documentclass[DIVcalc,twoside]{scrartcl}
 
\documentclass[DIVcalc,twoside]{scrartcl}
 
\begin{document}
 
\begin{document}
 
\noindent\framebox{\rule{0pt}{\textheight}\rule{\textwidth}{0pt}}
 
\noindent\framebox{\rule{0pt}{\textheight}\rule{\textwidth}{0pt}}
 
\end{document}
 
\end{document}
</pre>
+
</texcode>
 +
 
 +
== ConTeXt ==
 +
 
 +
The following code duplicates the <tt>scrartcl</tt> calculations to set the text area and produces a similar sample document, again with a framed box to show the text area.  Note that, because this depends on <cmd>lineheight</cmd> and sets the text area width based on a measurement of a typeset alphabet, it should be applied <i>after</i> any font setup.
 +
 
 +
<texcode>
 +
% Set binding correction value (mode=BCOR turns it on).
 +
\doifmodeelse{BCOR}{\def\bindingcorr{3mm}}{\def\bindingcorr{0pt}}
  
ConTeXt:
+
% Set visible page width.
<pre>
+
\newdimen\PageWidth
\def\BCOR{3mm}% eventual bounding correction
+
\PageWidth=\dimexpr(\paperwidth-\bindingcorr)
\newdimen\PageWidth \PageWidth=\paperwidth
+
 
\doifmode{BCOR}{\PageWidth=\dimexpr(\PageWidth-\BCOR)}
+
% Determine the paper aspect ratio.
 
\edef\Ratio{\withoutpt{\the\dimexpr(2\paperheight/(\PageWidth/32768))}}
 
\edef\Ratio{\withoutpt{\the\dimexpr(2\paperheight/(\PageWidth/32768))}}
 +
 +
% Set the textarea width to 2.6 alphabets.
 
\setbox\scratchbox\hbox{\dorecurse{26}{\character\recurselevel}}
 
\setbox\scratchbox\hbox{\dorecurse{26}{\character\recurselevel}}
\newdimen\Width \newdimen\Height \newdimen\Back
+
\newdimen\Width \Width=\dimexpr(2.6\wd\scratchbox)
\Width=\dimexpr(2.6\wd\scratchbox) \Height=\dimexpr(\Ratio\Width)
+
 
\doifmodeelse{oneside}{\Back=\dimexpr((\PageWidth - \Width) / 2)}
+
% Set the textarea height proportional to the width.
     {\Back=\dimexpr((\PageWidth - \Width) / 3)}
+
\newdimen\Height \Height=\dimexpr(\Ratio\Width)
\doifmode{BCOR}{\Back=\dimexpr(\Back + \BCOR)}
+
 
 +
% Set the margin/gutter widths to be equal on a full spread.
 +
\newdimen\Back
 +
\doifmodeelse{oneside}
 +
    {\Back=\dimexpr(((\PageWidth - \Width) / 2) + \bindingcorr)}
 +
     {\Back=\dimexpr(((\PageWidth - \Width) / 3) + \bindingcorr)}
 +
 
 +
% Set the top and bottom margins in a 1:2 ratio, ignoring headers.
 
\edef\Top{\the\dimexpr((\paperheight - \Height) / 3 - 3\lineheight)}
 
\edef\Top{\the\dimexpr((\paperheight - \Height) / 3 - 3\lineheight)}
 +
 +
% Redefine \Height to include header and footer space.
 
\Height=\dimexpr(\Height + 8\lineheight)
 
\Height=\dimexpr(\Height + 8\lineheight)
\setuplayout[backspace=\the\Back,height=\the\Height,width=\the\Width,
+
 
header=2\lineheight,headerdistance=\lineheight,
+
% Set up the page layout using the calculated parameters.
footer=2\lineheight,footerdistance=3\lineheight,topspace=\Top]
+
\setuplayout[
 +
    backspace=\the\Back,
 +
    height=\the\Height,
 +
    width=\the\Width,
 +
    header=2\lineheight,
 +
    headerdistance=\lineheight,
 +
    footer=2\lineheight,
 +
    footerdistance=3\lineheight,
 +
    topspace=\Top]
  
 
\starttext
 
\starttext
 
\framed[width=\textwidth,height=\textheight]{}
 
\framed[width=\textwidth,height=\textheight]{}
 
\stoptext
 
\stoptext
</pre>
+
</texcode>
 +
 
 +
This can be processed with a <code>-mode=BCOR</code> option on <code>texexec</code> to activate the binding correction, or with a <code>-mode=oneside</code> option to activate the single-sided page layout rather than the (default) double-sided version.
  
In the beta version of ConTeXt, there is probably a better way to achieve the
+
The module t-typearea.tex is available from http://pmrb.free.fr/work/OS/ConTeXt/
same...
 

Revision as of 18:20, 1 April 2006

< From LaTeX to ConTeXt >

LaTeX

The typearea style from the KOMA package (used per default in the KOMA classes) does some fairly sophisticated calculations to determine an optimal page layout, with the text width set in terms of average characters-per-line, and the text height and location set to provide pleasing proportions based on that and the paper proportions. A sample document (with a framebox to show the text area) is simply:

\documentclass{article}
\usepackage[DIVcalc,twoside]{typearea}
\begin{document}
\noindent\framebox{\rule{0pt}{\textheight}\rule{\textwidth}{0pt}}
\end{document}

or

\documentclass[DIVcalc,twoside]{scrartcl}
\begin{document}
\noindent\framebox{\rule{0pt}{\textheight}\rule{\textwidth}{0pt}}
\end{document}

ConTeXt

The following code duplicates the scrartcl calculations to set the text area and produces a similar sample document, again with a framed box to show the text area. Note that, because this depends on \lineheight and sets the text area width based on a measurement of a typeset alphabet, it should be applied after any font setup.

% Set binding correction value (mode=BCOR turns it on).
\doifmodeelse{BCOR}{\def\bindingcorr{3mm}}{\def\bindingcorr{0pt}}

% Set visible page width.
\newdimen\PageWidth
\PageWidth=\dimexpr(\paperwidth-\bindingcorr)

% Determine the paper aspect ratio.
\edef\Ratio{\withoutpt{\the\dimexpr(2\paperheight/(\PageWidth/32768))}}

% Set the textarea width to 2.6 alphabets.
\setbox\scratchbox\hbox{\dorecurse{26}{\character\recurselevel}}
\newdimen\Width \Width=\dimexpr(2.6\wd\scratchbox)

% Set the textarea height proportional to the width.
\newdimen\Height \Height=\dimexpr(\Ratio\Width)

% Set the margin/gutter widths to be equal on a full spread.
\newdimen\Back
\doifmodeelse{oneside}
    {\Back=\dimexpr(((\PageWidth - \Width) / 2) + \bindingcorr)}
    {\Back=\dimexpr(((\PageWidth - \Width) / 3) + \bindingcorr)}

% Set the top and bottom margins in a 1:2 ratio, ignoring headers.
\edef\Top{\the\dimexpr((\paperheight - \Height) / 3 - 3\lineheight)}

% Redefine \Height to include header and footer space.
\Height=\dimexpr(\Height + 8\lineheight)

% Set up the page layout using the calculated parameters.
\setuplayout[
     backspace=\the\Back,
     height=\the\Height,
     width=\the\Width,
     header=2\lineheight,
     headerdistance=\lineheight,
     footer=2\lineheight,
     footerdistance=3\lineheight,
     topspace=\Top]

\starttext
\framed[width=\textwidth,height=\textheight]{}
\stoptext

This can be processed with a -mode=BCOR option on texexec to activate the binding correction, or with a -mode=oneside option to activate the single-sided page layout rather than the (default) double-sided version.

The module t-typearea.tex is available from http://pmrb.free.fr/work/OS/ConTeXt/