ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: h h extern <pragma@wxs.nl>
Subject: Re: alignment questions
Date: Sun, 13 Mar 2005 19:45:16 +0100	[thread overview]
Message-ID: <42348A3C.3060800@wxs.nl> (raw)
In-Reply-To: <m2ekekcumb.fsf@levana.de>

Patrick Gundlach wrote:
> Hello *,
> 
> 
> inspired by Gerben's question, I did some experimenting with \framed.
> 
> I'd like to get A[text]B, where text is some long thing in a framed
> box like \framed[width=5cm] {\input tufte \par}.
> 
> There are three different ways of aligning the three objects:
> 
> 
> (A and B on the same baseline as the first row)
> 
> A We  thrive  in  information- B
> -------------------------------
>   thick worlds because of  our
>   marvelous and  everyday  ca-
> 
> 
> (A and B in the middle of the box, not necessarily on the same
> baseline as a line in the box)
> 
>   criminate, distinguish, screen, 
> A pigeonhole,  pick  over,  sort, B
>   integrate,    blend,   inspect,
> 
> 
> (A and B on the same baseline as the last row)
> 
>   from the chaff and seperate
> A the sheeps from the  goats. B
> --------------------------------
> 
> 
> 
> I was unable to get any of these alignments.

one way is to put things in a box and do some measuring and such; however, then 
you need to know a bit about the position of the baseline (measurethe middle 
box, and use a dummy framed around A and B with that height set etc)

the other way is to use the following extensions (i made the dislocator 
installable so that you can hook in your own code if needed)


\unprotect

\def\stoplocalframed
   {\dontshowcomposition
    \@@stopframedorientation
    \ifboxhasformat
      \ifx\localwidth\v!fit
        \ifreshapeframebox\doreshapeframedbox\fi
        \boxhaswidthfalse
      \else\ifx\localwidth\v!fixed
        \boxhaswidthfalse
      \else
        \resetshapeframebox
      \fi\fi
    \else
      \resetshapeframebox
    \fi
    \ifboxhaswidth
      \wd\framebox\!!widtha
    \fi
    \ifboxhasheight
      \ht\framebox\!!heighta
    \fi
    \doifvalue{\@@framed\c!empty}\v!yes
      {\setbox\scratchbox\null
       \wd\scratchbox\wd\framebox
       \ht\scratchbox\ht\framebox
       \dp\scratchbox\dp\framebox
       \setbox\framebox\box\scratchbox}%
    \stopregistercolor
    \docolorframebox
    \ifboxhasoffset
      \dooffsetframebox
    \fi
    \ifboxisoverlaid \else
      \dolocateframebox
    \fi
    \ifx\postprocessframebox\relax \else
      \let\next\postprocessframebox
      \let\postprocessframebox\relax % prevent nesting
      \next\framebox
    \fi
    \edef\overlaylinecolor{\framedparameter\c!framecolor}%
    \edef\overlaylinewidth{\the\ruledlinewidth}% \@@...
    \ifboxhasframe % real or invisible frame
      \doframedbox
    \fi
    \doifvaluesomething{\@@framed\c!background}\dobackedbox
    \handleframedlocator\@@locallocation
    \box\framebox
    \egroup
    \egroup}

\def\installframedlocator#1#2%
   {\setvalue{\??ol:\c!location:#1}{#2}}

\def\handleframedlocator#1%
   {\getvalue{\??ol:\c!location:#1}}

\def\doprelocframedbox#1%
   {\scratchdimen#1\relax
    \advance\scratchdimen \ruledlinewidth
    \ifboxhasoffset
      \advance\scratchdimen \framedparameter\c!offset
    \fi
    \scratchskip\ht\framebox
    \advance\scratchskip-\scratchdimen}

\installframedlocator \v!hanging % best with strut=no
   {\dp\framebox\ht\framebox
    \ht\framebox\zeropoint}

\installframedlocator \v!depth
   {\scratchdimen\ht\framebox
    \advance\scratchdimen -\strutdp
    \ht\framebox\scratchdimen
    \dp\framebox\strutdp
    \box\framebox}

\installframedlocator \v!height
   {\scratchdimen\ht\framebox
    \advance\scratchdimen -\strutht
    \ht\framebox\strutht
    \dp\framebox\scratchdimen
    \box\framebox}

\installframedlocator \v!high
   {\doprelocframedbox\strutht
    \setbox\framebox\hbox{\lower\scratchskip\box\framebox}%
    \ht\framebox\strutht
    \dp\framebox\strutdp
    \hbox{\box\framebox}}

\installframedlocator \v!line
   {\setbox\framebox\hbox{\lower.5\ht\framebox\box\framebox}%
    \ht\framebox.5\lineheight
    \dp\framebox.5\lineheight
    \hbox{\box\framebox}}

\installframedlocator \v!low
   {\doprelocframedbox\strutdp
    \setbox\framebox\hbox{\lower\scratchdimen\box\framebox}%
    \ht\framebox\strutht
    \dp\framebox\strutdp
    \box\framebox}

\installframedlocator \v!top
   {\doprelocframedbox\strutht
    \setbox\framebox\hbox{\lower\scratchskip\box\framebox}%
    \ht\framebox\scratchdimen
    \dp\framebox\scratchskip
    \hbox{\box\framebox}}

\installframedlocator \v!middle
   {\scratchdimen.5\ht\framebox
    \setbox\framebox\hbox{\lower\scratchdimen\box\framebox}%
    \ht\framebox\scratchdimen
    \dp\framebox\scratchdimen
    \hbox{\box\framebox}}

\installframedlocator \v!lohi
   {\handleframedlocator\v!middle}

\installframedlocator \v!bottom
   {\doprelocframedbox\strutdp
    \setbox\framebox\hbox{\lower\scratchdimen\box\framebox}%
    \ht\framebox\scratchskip
    \dp\framebox\scratchdimen
    \hbox{\box\framebox}}

\starttext

\ruledhbox
   {A
    \framed[width=2cm,align=middle,location=hanging]{location\\equals\\hanging}
    \framed[width=2cm,align=middle,location=depth]  {location\\equals\\depth}
    \framed[width=2cm,align=middle,location=height] {location\\equals\\height}
    B}

\vskip2cm

\ruledhbox
   {A
    \framed[width=2cm,align=middle,location=low]    {location\\equals\\low}
    \framed[width=2cm,align=middle,location=line]   {location\\equals\\line}
    \framed[width=2cm,align=middle,location=high]   {location\\equals\\high}
    B}

\vskip2cm

\ruledhbox
  {A
   \framed[width=2cm,align=middle,location=top]    {location\\equals\\top}
   \framed[width=2cm,align=middle,location=bottom] {location\\equals\\bottom}
   \framed[width=2cm,align=middle,location=lohi]   {location\\equals\\lohi}
   \framed[width=2cm,align=middle,location=middle] {location\\equals\\middle}
   B}

\stoptext

(hanging, depth and low were already present)

check for compatibility -)

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
      tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------

  parent reply	other threads:[~2005-03-13 18:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-12 23:27 Patrick Gundlach
2005-03-13 10:25 ` Willi Egger
2005-03-13 16:39   ` Patrick Gundlach
2005-03-13 11:02 ` Willi Egger
2005-03-13 11:22 ` Vit Zyka
2005-03-13 11:44   ` Taco Hoekwater
2005-03-14  9:53     ` Patrick Gundlach
2005-03-13 12:24 ` Willi Egger
2005-03-13 18:45 ` h h extern [this message]
2005-03-14  9:03   ` Vit Zyka
2005-03-14  9:31   ` Patrick Gundlach

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42348A3C.3060800@wxs.nl \
    --to=pragma@wxs.nl \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).