ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Vertical alignment of arbitrary text
@ 2001-05-12 14:35 Berend de Boer
  2001-05-13 13:04 ` Vertical alignment of arbitrary text, berends o'reilly head Hans Hagen
  0 siblings, 1 reply; 3+ messages in thread
From: Berend de Boer @ 2001-05-12 14:35 UTC (permalink / raw)


Hello Hans,

Is there a construct in ConTeXt to align two arbitrary pieces of text?
For example I wanted a chapter number and the contents of that chapter
to be aligned.

After much blood, sweat and tears I came up with this:

-------------------------------
\def\SimpleHead#1%
  {\vtop{\rightaligned{{\switchtobodyfont[36pt]\ }}\par
         \rightaligned{\startnarrower[3*left] #1\stopnarrower}}}

\def\myContents#1#2#3%
  {\sym{$\bullet$} {\bs #2}\par}

\newdimen\myheight
\newdimen\mydepth
\newbox\myboxA
\newbox\myboxB

\def\ContentsHead#1#2%
  {\setbox\myboxA=\vbox{\hsize=5cm
                    \startframedtext
                    [frame=off,background=screen,width=5cm]%
                    In this chapter:\par
                    \startalignment[right]
                    \placelist
                      [section]
                      [criterium=chapter,
                       alternative=command,
                       command=\myContents,
                       style=boldslanted,
                       align=left,
                       interaction=all,
                       before=,after=]%                 
                    \stopalignment
                    \stopframedtext}%
   \myheight=\ht\myboxA
   \mydepth=\dp\myboxA
   \ht\myboxA=0pt
   \advance\mydepth by \myheight
   \dp\myboxA=\mydepth
   \setbox\myboxB=\vbox
      {\hsize=8cm \rightaligned{{\switchtobodyfont[36pt]#1}}\par
       \startalignment[left,broad] #2\stopalignment}%
   \myheight=\ht\myboxB
   \mydepth=\dp\myboxB
   \ht\myboxB=0pt
   \advance\mydepth by \myheight
   \dp\myboxB=\mydepth
   \box\myboxA\hfill\box\myboxB}

\def\myhead#1#2%
  {\doifemptyelse{#1}{\SimpleHead{#2}}{\ContentsHead{#1}{#2}}}

\setuphead
  [chapter]
  [header=empty,
   style=\bsd,
   command=\myhead,
   page=right,
   after={\blank[2*big]}]
-------------------------------

But is there a better way? This took me surprisingly long and I had to
use the visual debugger to get a clue what was going on. With the
height of both boxes to 0 I've more or less alignment them I think.

(I attempt to emulate the O'Reilly format)

Groetjes,

Berend. (-:


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Vertical alignment of arbitrary text, berends o'reilly head
  2001-05-12 14:35 Vertical alignment of arbitrary text Berend de Boer
@ 2001-05-13 13:04 ` Hans Hagen
  2001-05-14 14:45   ` Berend de Boer
  0 siblings, 1 reply; 3+ messages in thread
From: Hans Hagen @ 2001-05-13 13:04 UTC (permalink / raw)
  Cc: ntg-context

Hi Berend, 

>Is there a construct in ConTeXt to align two arbitrary pieces of text?
>For example I wanted a chapter number and the contents of that chapter
>to be aligned.
>
>After much blood, sweat and tears I came up with this:

well, given the sun, i only had to sweat a bit: 

% output=pdftex

\setuplist
  [section]
  [style=boldslanted,
   align=left,
   interaction=all,
   symbol=1, 
   width=1em,
   pagenumber=no,
   before=,
   after=]                 

\setuphead
  [chapter]
  [header=empty,
   style=BigHeadFont,
   alternative=command,
   command=\ContentsHead, 
   page=right,
   after={\blank[2*big]}]

\definefont[BigHeadFont][Serif at 36pt]

\def\ContentsHead#1#2%
  {%\setupframed[frame=off]
   \framed[width=\hsize,offset=overlay]
     {\placesidebyside
        {\doifelsenothing{#1}
           {\framed[width=.6\hsize]{}} % dummy               
           {\framed

[width=.6\hsize,offset=1em,strut=no,align=right,background=screen] 
              {In this chapter: \blank
               \placelist[section][criterium=chapter]}}}
        {\framed
           [width=.4\hsize,offset=1em,strut=no,align=left]
           {#1\par#2}}}}

\starttext 

\title {Berend} 

\chapter {Berend} 

\section {Botje} 
\section {Botje} 
\section {Botje} 

\stoptext 

Makes a nice example for the example suite

>-------------------------------
>\def\SimpleHead#1%
>  {\vtop{\rightaligned{{\switchtobodyfont[36pt]\ }}\par
>         \rightaligned{\startnarrower[3*left] #1\stopnarrower}}}
>
>\def\myContents#1#2#3%
>  {\sym{$\bullet$} {\bs #2}\par}
>
>\newdimen\myheight
>\newdimen\mydepth
>\newbox\myboxA
>\newbox\myboxB
>
>\def\ContentsHead#1#2%
>  {\setbox\myboxA=\vbox{\hsize=5cm
>                    \startframedtext
>                    [frame=off,background=screen,width=5cm]%
>                    In this chapter:\par
>                    \startalignment[right]
>                    \placelist
>                      [section]
>                      [criterium=chapter,
>                       alternative=command,
>                       command=\myContents,
>                       style=boldslanted,
>                       align=left,
>                       interaction=all,
>                       before=,after=]%                 
>                    \stopalignment
>                    \stopframedtext}%
>   \myheight=\ht\myboxA
>   \mydepth=\dp\myboxA
>   \ht\myboxA=0pt
>   \advance\mydepth by \myheight
>   \dp\myboxA=\mydepth
>   \setbox\myboxB=\vbox
>      {\hsize=8cm \rightaligned{{\switchtobodyfont[36pt]#1}}\par
>       \startalignment[left,broad] #2\stopalignment}%
>   \myheight=\ht\myboxB
>   \mydepth=\dp\myboxB
>   \ht\myboxB=0pt
>   \advance\mydepth by \myheight
>   \dp\myboxB=\mydepth
>   \box\myboxA\hfill\box\myboxB}
>
>\def\myhead#1#2%
>  {\doifemptyelse{#1}{\SimpleHead{#2}}{\ContentsHead{#1}{#2}}}
>
>\setuphead
>  [chapter]
>  [header=empty,
>   style=\bsd,
>   command=\myhead,
>   page=right,
>   after={\blank[2*big]}]
>-------------------------------
>
>But is there a better way? This took me surprisingly long and I had to
>use the visual debugger to get a clue what was going on. With the
>height of both boxes to 0 I've more or less alignment them I think.
>
>(I attempt to emulate the O'Reilly format)
>
>Groetjes,
>
>Berend. (-:
>
>
-------------------------------------------------------------------------
                                  Hans Hagen | PRAGMA ADE | pragma@wxs.nl
                      Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
 tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Vertical alignment of arbitrary text, berends o'reilly head
  2001-05-13 13:04 ` Vertical alignment of arbitrary text, berends o'reilly head Hans Hagen
@ 2001-05-14 14:45   ` Berend de Boer
  0 siblings, 0 replies; 3+ messages in thread
From: Berend de Boer @ 2001-05-14 14:45 UTC (permalink / raw)
  Cc: ntg-context

Hans Hagen <pragma@wxs.nl> writes:

> well, given the sun, i only had to sweat a bit: 

At least I'm glad that it isn't a build-in command :-)

Thanks!

Berend. (-:


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-05-14 14:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-12 14:35 Vertical alignment of arbitrary text Berend de Boer
2001-05-13 13:04 ` Vertical alignment of arbitrary text, berends o'reilly head Hans Hagen
2001-05-14 14:45   ` Berend de Boer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).