Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can 0123456789 be aligned as shown in red: Same baseline as abcdefghij, aligned left with ABCDEFGHIJKL?

\vlines are just for illustration. I am designing a poster where exact text positioning matters.

\documentclass{article}
\usepackage[absolute,overlay]{textpos}

\begin{document}
\begin{textblock*}{10cm}(5cm,5cm)
\noindent\vline
\hfill\begin{tabular}{l@{}}
  ABCDEFGHIJ\\
  ABCDEFGHIJKL\\
  ABCDEFGH
\end{tabular}
\vline
\end{textblock*}

\begin{textblock*}{10cm}(5cm,10cm)
  \hfill 0123456789
  \vline
\end{textblock*}

\begin{textblock*}{10mm}(5cm,10cm)
\noindent\vline
  abcdefghij\\
  abcdefghijkl\\
  abcdefgh
\end{textblock*}

\end{document}

enter image description here

share|improve this question
    
Just like Heiko's great package zref, there are many answers on this site using a solution widely known to the residents as \tikzmark solution. It requires TikZ package which is a little overkill but positioning is a very easy task. –  percusse Sep 9 '12 at 0:34
add comment

3 Answers

up vote 8 down vote accepted

The TeX compiler pdfTeX (inventor), LuaTeX and XeTeX support the feature \pdfsavepos that allows to record the absolute positions in the .aux file. Module zref-savepos of package zref provides an easier interface. The positions are numbers, unit is 1sp.

It helps, if there are fixed positions that can be used for the correction of the position of the string "0123456789". For the horizontal correction the positions ABC and 012 are used whose horizontal component does not change.

In case of the vertical correction it is more difficult, because the alignment is on the baseline and the vertical position depends on the height of the first line, for example. The following example measures the differnce before the first paragraph and the base line inside the text block and fixes the vertical position of "0123456789" by assuming the text blocks start at the same vertical position (10cm).

\documentclass{article}
\usepackage[absolute,overlay]{textpos}

\usepackage{zref-savepos}

\begin{document}
\begin{textblock*}{10cm}(5cm,5cm)
\noindent\vline
\hfill\begin{tabular}{l@{}}
  \zsavepos{ABC}%
  ABCDEFGHIJ\\
  ABCDEFGHIJKL\\
  ABCDEFGH
\end{tabular}
\vline
\end{textblock*}

\begin{textblock*}{10cm}(5cm,10cm)
  \kern\dimexpr
    \zposy{abc-pre}sp-\zposy{abc}sp
    -\zposy{012-pre}sp+\zposy{012}sp
  \relax
  \zsavepos{012-pre}%
  \noindent
  \zsavepos{012}%
  \kern\dimexpr\zposx{ABC}sp-\zposx{012}sp\relax
  0123456789 \vline
\end{textblock*}

% 10mm fixed to 10cm to avoid overfull \hboxes
\begin{textblock*}{10cm}(5cm,10cm)
  \zsavepos{abc-pre}%
  \noindent\vline
  \zsavepos{abc}abcdefghij\\
  abcdefghijkl\\
  abcdefgh
\end{textblock*}

\end{document}

Result

share|improve this answer
    
Wow :-) Could I ask two questions: 1. Could the code be simplified if the height of the lines abcdefghij and 0123456789 were the same? (please don't replace in your original code) 2. I get three bad boxes - normal? –  Frank Seifert Sep 8 '12 at 23:16
    
If the first lines have the same height, you do not need the vertical correction. the width of the third text block is too small, perhaps a typo: 10mm -> 10cm. –  Heiko Oberdiek Sep 8 '12 at 23:58
    
Yes, typo caused bad boxes, sorry. Cool -- Thanks a lot Heiko! –  Frank Seifert Sep 9 '12 at 0:43
add comment

There are already two good approaches, but I'd like to add one to illustrate some ideas the LaTeX3 team have developed in using 'coffins': boxes with multiple handles for laying out designs. At the moment, this is not perfect: there are some concepts we perhaps need to add to the code, in particular vertical boxes which adopt a 'maximum' width and absolute page positioning (everything is relative at present).

The idea of the coffins approach is we can create design layout with some form of description that is understandable. Here, we have three blocks (I'll call them A, B and C). From the example, the description seems to be as follows. Block A (ABC...) is typeset left-aligned. Block B (012...) is a single line and is typeset exactly 5 cm below block A (measuring top to top) with no horizontal offset. Block C (abc...) is typeset exactly 5 cm to the left of block B (left-edge to left-edge), with the baseline of the first line of block C aligned with the baseline of block B. The entire construct is positioned such that the top-left corner of the enclosing box is positioned at (5 cm, 5 cm) on the page. This translates into

\documentclass{article}
\usepackage[absolute,overlay]{textpos}
\usepackage{xcoffins}
\NewCoffin{\CoffinA}
\NewCoffin{\CoffinB}
\NewCoffin{\CoffinC}
\begin{document}
\SetHorizontalCoffin{\CoffinA}{%
  \begin{tabular}{@{}l@{}}
    ABCDEFGHIJ\\
    ABCDEFGHIJKL\\
    ABCDEFGH
  \end{tabular}
}
\SetHorizontalCoffin{\CoffinB}{0123456789}
\JoinCoffins{\CoffinA}[t,l]{\CoffinB}[t,l](0 cm, -5 cm)
\SetVerticalCoffin{\CoffinC}{10 cm}{%
  \noindent
  abcdefghij\\
  abcdefghijkl\\
  abcdefgh
}
\JoinCoffins{\CoffinA}[\CoffinB-B,l]{\CoffinC}[T,l](-5 cm, 0 cm)
\begin{textblock*}{10cm}(5 cm, 5 cm)
  \noindent
  \TypesetCoffin{\CoffinA}%
\end{textblock*}
\end{document}

(There are other orders I could do the same thing.)

enter image description here

share|improve this answer
1  
I can imagine implementing something like \PlaceCoffin or \PositionCoffin for typesetting a coffin relative to handles for the page itself: I guess that would make this a bit cleaner. –  Joseph Wright Sep 9 '12 at 8:49
add comment

Perhaps using a couple of instances of tabular*

screenshot

Note that the tabular* takes an extra argument <width> compared to the regular tabular environment.

I used \extracolsep{\fill} to fill space between the columns. As long as you ensure the second columns p{<width>} have the same width, then this will give you what you want.

\documentclass{article}
\usepackage[absolute,overlay]{textpos}

\begin{document}
\begin{textblock*}{10cm}(5cm,5cm)
\noindent
\begin{tabular*}{\textwidth}{|l@{\extracolsep{\fill}}p{3cm}|}
  &ABCDEFGHIJ\\
  &ABCDEFGHIJKL\\
  &ABCDEFGH
\end{tabular*}
\vline
\end{textblock*}

\begin{textblock*}{10cm}(5cm,10cm)
\noindent
\begin{tabular*}{\textwidth}{|l@{\extracolsep{\fill}}p{3cm}|}
  abcdefghij    & 0123456789\\
  abcdefghijkl  &\\
  abcdefgh      &
\end{tabular*}
\end{textblock*}


\end{document}
share|improve this answer
    
Thanks a lot for your answer! If at all possible, I would like to avoid having to specify the width of the top-right table. Makes it inflexible should its contents change. –  Frank Seifert Sep 8 '12 at 21:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.