W3C home > Mailing lists > Public > www-xsl-fo@w3.org > March 2003

Re: How to vertically center text and image?

From: G. Ken Holman <gkholman@CraneSoftwrights.com>
Date: Wed, 26 Mar 2003 09:32:22 -0500
Message-Id: <5.2.0.9.0.20030326092702.02beec10@pop.storm.ca>
To: www-xsl-fo@w3.org
At 2003-03-26 14:22 +0100, mes@komma.zedat.fu-berlin.de wrote:
>Hi,
>
>my text is smaller as image,
>how can i vertically center the text?
>Example:
>      .........
>Text . Image . Text
>      .........

An interesting challenge!


>but not
>
>Text ......... Text
>      . Image .
>      .........

XSL-FO "sits" graphics on top of lines oriented along the text ... not the 
other way around .... so I wouldn't have expected what you drew above, I 
always witness:

      .........
      . Image .
Text ......... Text

Using alignment-adjust you can change the default use of the text baseline 
for the bottom of the image, to be any other baseline for the bottom of the 
image ... but the image still sits *on top* of the given baseline.

I then noted that a length can be used for alignment-adjust ... but this 
means you will have to know a priori what the height of your graphic is.

I've attached the result shown for the following:

   <block space-before="1cm" font-size="20pt">
     -2cm : with a long enough sentence that will wrap to the next line
      in such a nature
     <external-graphic alignment-adjust="-2cm"
       src='url("tight.bmp")'/>
     to show how the text interacts with the image that has been aligned
   </block>

which gets you the result, but not by "vertically centring the text" which 
is what you asked for.  I don't think there is a way to "vertically centre 
the text" ... I think you have to "vertically centre the graphic" by 
knowing the height of the graphic.

An interesting task!

I hope this helps.

................. Ken 

--
Upcoming hands-on in-depth XSLT/XPath and/or XSL-FO
                              North America:      June 16-20, 2003

G. Ken Holman                mailto:gkholman@CraneSoftwrights.com
Crane Softwrights Ltd.         http://www.CraneSoftwrights.com/f/
Box 266, Kars, Ontario CANADA K0A-2E0   +1(613)489-0999 (F:-0995)
ISBN 0-13-065196-6                      Definitive XSLT and XPath
ISBN 0-13-140374-5                              Definitive XSL-FO
ISBN 1-894049-08-X  Practical Transformation Using XSLT and XPath
ISBN 1-894049-10-1              Practical Formatting Using XSL-FO
Male Breast Cancer Awareness http://www.CraneSoftwrights.com/f/bc


test-align.gif
(image/gif attachment: test-align.gif)

Received on Wednesday, 26 March 2003 09:32:34 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 3 October 2007 16:06:10 GMT