Das ist eine TeX-Frage! Im folgenden Beispiel werden zwei vertikale Boxen dargestellt, die rechte Box wird nach rechts und nach oben um die Maße \wd und \ht verschoben, die aus der Box \mybox ermittelt wurden. Um eine korrekte Ausrichtung zu erhalten, besonders eine Registerhaltigkeit, muß der Wert \vskip3\lineskip verwendet werden. Kann jemand erklären, warum gerade dieser Wert notwendig ist und wie TeX diesen berechnet? (Siehe auch TeXbook,S.78 u.a.)

Open in writeLaTeX
\newbox\mybox%
\newbox\yourbox%
\newbox\ourbox%
\newdimen\raisefactor%
\newdimen\shiftfactor%
\setbox\mybox=\vbox{\hsize=4cm a bcd ef g h ij klmab cdefghijklm abc defghij k l m a b c d e f g h i j k l m a b c d e f g h i j k l m a b
c d e f g h i j k l e f g h i j k l m a b c d e f g h i j k l m a bc d e f g h i j j k l m a b c d e f g h i j k l m k l m  k l m a b c d e f g h i j k l m a b c d e f g h i j k l m a bc d e f g h i j k l e f g h i kj k l m a b c d e f g h i j k l m a bc d e f g h i j j k l m a bc d e f g h i j k l ma b c d e f g h i j k l m a b c d e f g h i j k l m a bc d e f g h i j k l e f g h i j k l m a b c d e f g h i j k l m a bc d e f g h i j j k l m a bc d e f g h i j k l m }%
\setbox\yourbox=\vtop{\vbox{\copy\mybox}}%
\setbox\ourbox=\vtop{\vbox{\copy\mybox}}%
\the\ht\yourbox \the\wd\yourbox%
\hskip1cm\the\ht\ourbox \the\wd\ourbox%
\raisefactor=\the\ht\yourbox%
\shiftfactor=\the\wd\yourbox%
\hrule%
\vtop{\vtop{\unvbox\yourbox}\vskip-3\lineskip \vskip-1\raisefactor%
  \hskip1\shiftfactor\vtop{\unvbox\ourbox}}%
\hrule%
\bye%

gefragt 09 Okt '14, 23:48

ctansearch's gravatar image

ctansearch
(ausgesetzt)
Akzeptiert-Rate: 18%

bearbeitet 09 Okt '14, 23:49


Die -3\lineskip sind eher Zufall, wie man bereits mit

Open in writeLaTeX
\lineskip=0pt
\newbox\mybox%
\newbox\yourbox%
\newbox\ourbox%
\newdimen\raisefactor%
\newdimen\shiftfactor%
\setbox\mybox=\vbox{\hsize=4cm a bcd ef g h ij klmab cdefghijklm abc defghij k l m a b c d e f g h i j k l m a b c d e f g h i j k l m a b
c d e f g h i j k l e f g h i j k l m a b c d e f g h i j k l m a bc d e f g h i j j k l m a b c d e f g h i j k l m k l m  k l m a b c d e f g h i j k l m a b c d e f g h i j k l m a bc d e f g h i j k l e f g h i kj k l m a b c d e f g h i j k l m a bc d e f g h i j j k l m a bc d e f g h i j k l ma b c d e f g h i j k l m a b c d e f g h i j k l m a bc d e f g h i j k l e f g h i j k l m a b c d e f g h i j k l m a bc d e f g h i j j k l m a bc d e f g h i j k l m }%
\setbox\yourbox=\vtop{\vbox{\copy\mybox}}%
\setbox\ourbox=\vtop{\vbox{\copy\mybox}}%
\the\ht\yourbox \the\wd\yourbox%
\hskip1cm\the\ht\ourbox \the\wd\ourbox%
\raisefactor=\the\ht\yourbox%
\shiftfactor=\the\wd\yourbox%
\hrule%
\vtop{\vtop{\unvbox\yourbox}\vskip-3\lineskip \vskip-1\raisefactor%
  \hskip1\shiftfactor\vtop{\unvbox\ourbox}}%
\hrule%
\bye%

-3klzzwxh:0001ineskip ist nicht korrekt

erkennen kann. Tatsächlich hängt das sehr von der tatsächlichen Höhe der ersten bzw. der tatsächlichen Tiefe der letzten Zeile in der Box ab:

Open in writeLaTeX
\newbox\mybox%
\newbox\yourbox%
\newbox\ourbox%
\newdimen\raisefactor%
\newdimen\shiftfactor%
\lineskip0pt
\setbox\mybox=\vbox{\hsize=4cm \strut a bcd ef g h ij klmab cdefghijklm abc defghij k l m a b c d e f g h i j k l m a b c d e f g h i j k l m a b
c d e f g h i j k l e f g h i j k l m a b c d e f g h i j k l m a bc d e f g h i j j k l m a b c d e f g h i j k l m k l m  k l m a b c d e f g h i j k l m a b c d e f g h i j k l m a bc d e f g h i j k l e f g h i kj k l m a b c d e f g h i j k l m a bc d e f g h i j j k l m a bc d e f g h i j k l ma b c d e f g h i j k l m a b c d e f g h i j k l m a bc d e f g h i j k l e f g h i j k l m a b c d e f g h i j k l m a bc d e f g h i j j k l m a bc d e f g h i j k l m\strut }%
\setbox\yourbox=\vtop{\vbox{\copy\mybox}}%
\setbox\ourbox=\vtop{\vbox{\copy\mybox}}%
\the\ht\yourbox\space \the\wd\yourbox%
\hskip1cm\the\ht\ourbox\space \the\wd\ourbox%
\raisefactor=\the\ht\yourbox%
\shiftfactor=\the\wd\yourbox%
\hrule%
\vbox{\vtop{\unvbox\yourbox}\vskip-\raisefactor\vskip-\dp\strutbox \hskip\shiftfactor
  \vtop{\unvbox\ourbox}}%
\hrule%
\bye%

klzzwxh:0003pklzzwxh:0004trutbox ist schon besser

Du musst also berücksichtigen, dass Boxen bei TeX nicht nur eine Höhe, sondern auch eine Tiefe haben, und Dir überlegen, wo denn nun eigentlich die Grundlinie verläuft.

Ich habe mich hier eines kleinen Tricks bedient, um diese Tiefe (und nebenbei auch die Höhe) eindeutig zu definieren. Ohne den Trick geht es in diesem Fall auch, weil man aufgrund der Verwendung von \vbox für \mybox die Tiefe der letzten Zeile von \mybox noch bestimmen kann:

Open in writeLaTeX
\newbox\mybox%
\newbox\yourbox%
\newbox\ourbox%
\newdimen\raisefactor%
\newdimen\shiftfactor%
\lineskip0pt
\setbox\mybox=\vbox{\hsize=4cm a bcd ef g h ij klmab cdefghijklm abc defghij k l m a b c d e f g h i j k l m a b c d e f g h i j k l m a b
c d e f g h i j k l e f g h i j k l m a b c d e f g h i j k l m a bc d e f g h
i j j k l m a b c d e f g h i j k l m k l m  k l m a b c d e f g h i j k l m a
b c d e f g h i j k l m a bc d e f g h i j k l e f g h i kj k l m a b c d e f
g h i j k l m a bc d e f g h i j j k l m a bc d e f g h i j k l ma b c d e f g
h i j k l m a b c d e f g h i j k l m a bc d e f g h i j k l e f g h i j k l m
a b c d e f g h i j k l m a bc d e f g h i j j k l m a bc d e f g h i j k l
m}%
\setbox\yourbox=\vtop{\vbox{\copy\mybox}}%
\setbox\ourbox=\vtop{\vbox{\copy\mybox}}%
\the\ht\yourbox\space \the\wd\yourbox%
\hskip1cm\the\ht\ourbox\space \the\wd\ourbox%
\raisefactor=\the\ht\yourbox%
\shiftfactor=\the\wd\yourbox%
\hrule%
\vbox{\vtop{\unvbox\yourbox}\vskip-\raisefactor\vskip-\dp\mybox \hskip\shiftfactor
  \vtop{\unvbox\ourbox}}%
\hrule%
\bye%

klzzwxh:0009pklzzwxh:0010ybox ist noch besser

Was passiert nun, wenn man \lineskip nicht auf 0pt setzt? Nun, dann hat man in der äußeren \vbox zwei aufeinanderfolgende Boxen, deren vertikaler Abstand geringer als \lineskip ist, weshalb \lineskip automatisch addiert wird. Also muss man \lineskip wieder abziehen:

Open in writeLaTeX
\newbox\mybox%
\newbox\yourbox%
\newbox\ourbox%
\newdimen\raisefactor%
\newdimen\shiftfactor%
%\lineskip10pt
\setbox\mybox=\vbox{\hsize=4cm a bcd ef g h ij klmab cdefghijklm abc defghij k l m a b c d e f g h i j k l m a b c d e f g h i j k l m a b
c d e f g h i j k l e f g h i j k l m a b c d e f g h i j k l m a bc d e f g h
i j j k l m a b c d e f g h i j k l m k l m  k l m a b c d e f g h i j k l m a
b c d e f g h i j k l m a bc d e f g h i j k l e f g h i kj k l m a b c d e f
g h i j k l m a bc d e f g h i j j k l m a bc d e f g h i j k l ma b c d e f g
h i j k l m a b c d e f g h i j k l m a bc d e f g h i j k l e f g h i j k l m
a b c d e f g h i j k l m a bc d e f g h i j j k l m a bc d e f g h i j k l
m}%
\setbox\yourbox=\vtop{\vbox{\copy\mybox}}%
\setbox\ourbox=\vtop{\vbox{\copy\mybox}}%
\the\ht\yourbox\space \the\wd\yourbox%
\hskip1cm\the\ht\ourbox\space \the\wd\ourbox%
\raisefactor=\the\ht\yourbox%
\shiftfactor=\the\wd\yourbox%
\hrule%
\vbox{\vtop{\unvbox\yourbox}\vskip-\raisefactor\vskip-\dp\mybox\vskip-\lineskip \hskip\shiftfactor
  \vtop{\unvbox\ourbox}}%
\hrule%
\bye%

klzzwxh:0017ineskip ist auch dann zu beachten

Das funktioniert auch dann noch, wenn \lineskip einen vom Standardwert 1pt abweichenden Wert hat, wenn man beispielsweise im letzten Beispiel die auskommentierte Zeile aktiviert.

Und wieso waren nun -3\lineskip in Deinem Beispiel zufällig richtig? Waren sie gar nicht, sie waren nur zufällig fast richtig:

Open in writeLaTeX
\newbox\mybox%
\newbox\yourbox%
\newbox\ourbox%
\newdimen\raisefactor%
\newdimen\shiftfactor%
\setbox\mybox=\vbox{\hsize=4cm a bcd ef g h ij klmab cdefghijklm abc defghij k l m a b c d e f g h i j k l m a b c d e f g h i j k l m a b
c d e f g h i j k l e f g h i j k l m a b c d e f g h i j k l m a bc d e f g h
i j j k l m a b c d e f g h i j k l m k l m  k l m a b c d e f g h i j k l m a
b c d e f g h i j k l m a bc d e f g h i j k l e f g h i kj k l m a b c d e f
g h i j k l m a bc d e f g h i j j k l m a bc d e f g h i j k l ma b c d e f g
h i j k l m a b c d e f g h i j k l m a bc d e f g h i j k l e f g h i j k l m
a b c d e f g h i j k l m a bc d e f g h i j j k l m a bc d e f g h i j k l
m}%
\setbox\yourbox=\vtop{\vbox{\copy\mybox}}%
\setbox\ourbox=\vtop{\vbox{\copy\mybox}}%
\the\ht\yourbox\space \the\wd\yourbox%
\hskip1cm\the\ht\ourbox\space \the\wd\ourbox%
\raisefactor=\the\ht\yourbox%
\shiftfactor=\the\wd\yourbox%
\hrule%
\vbox{\vtop{\unvbox\yourbox}\vskip-\raisefactor\vskip-\dp\mybox\vskip-\lineskip \hskip\shiftfactor
  \vtop{\unvbox\ourbox}}%
\hrule%

\dimen255=\dp\mybox
\advance\dimen255 by \lineskip
\the\dp\mybox+\the\lineskip=\the\dimen255

\bye%

Hier der Wert für die tatsächlich korrekte Verschiebung

Die minimale Abweichung von weniger als 0,06 pt ist schlicht in diesem Fall nicht erkennbar (durch Rundungsfehler im Viewer kann sie aber bei schlechter Auflösung tatsächlich zufällig auch erkennbar werden).

Übrigens ist das ganze einfacher, wenn man für die horizontale Anordnung eben keine \vbox, sondern die dafür vorgesehene \hbox verwendet. Dann hat man beispielsweise das \lineskip-Problem nicht:

Open in writeLaTeX
\newbox\mybox
\newbox\yourbox
\newbox\ourbox
\setbox\mybox=\vbox{\hsize=4cm \strut a bcd ef g h ij klmab cdefghijklm abc defghij k l m a b c d e f g h i j k l m a b c d e f g h i j k l m a b
c d e f g h i j k l e f g h i j k l m a b c d e f g h i j k l m a bc d e f g h
i j j k l m a b c d e f g h i j k l m k l m  k l m a b c d e f g h i j k l m a
b c d e f g h i j k l m a bc d e f g h i j k l e f g h i kj k l m a b c d e f
g h i j k l m a bc d e f g h i j j k l m a bc d e f g h i j k l ma b c d e f g
h i j k l m a b c d e f g h i j k l m a bc d e f g h i j k l e f g h i j k l m
a b c d e f g h i j k l m a bc d e f g h i j j k l m a bc d e f g h i j k l
m\strut}%
\setbox\yourbox=\vtop{\vbox{\copy\mybox}}%
\setbox\ourbox=\vtop{\vbox{\copy\mybox}}%
\the\ht\yourbox\space \the\wd\yourbox
\hskip1cm\the\ht\ourbox\space \the\wd\ourbox
\hrule
\hbox{\vtop{\unvbox\yourbox}\hskip 1cm
  \vtop{\unvbox\ourbox}}%
\hrule
\bye

mit klzzwxh:0025box geht es einfacher

Ebenso muss man sich dann keine Gedanken darüber machen, was denn eigentlich passiert, wenn man in dem Beispiel \parskip auf einen von 0pt abweichenden negativen oder positiven Wert setzt und dieser womöglich auch noch glue enthält.

LaTeX-Anwendern sei übrigens empfohlen, nicht \vbox und \vtop, sondern schlicht \parbox zu verwenden. Ggf. kann für diese auch das Paket adjustbox nützlich sein, wenn es geht, Boxen nebeneinander auszurichten. Das Problem, dass man sich überlegen muss, wo denn nun eigentlich die Grundlinie verläuft, wird damit allerdings nicht komplett beseitigt. Das betrifft neben plainTeX-Anwendern auch die Anwender aller anderen TeX-Formate.

Permanenter link

beantwortet 10 Okt '14, 07:42

gast3's gravatar image

gast3
(ausgesetzt)
Akzeptiert-Rate: 53%

bearbeitet 11 Okt '14, 08:48

@IjonTichy

Vielen Dank erstmal für die ausführliche Antwort. Ich komme mit lineskip=0pt und hbox nicht zu den gleichen Ergebnissen, ausserdem habe ich vbox und vtop deshalb angewendet, weil erstens die Messung der Höhe bei vbox gegeben ist und bei vtop die Ausrichtung nach oben inbegriffen ist. Diese Vorteile will ich später wieder nutzen.

(10 Okt '14, 22:44) ctansearch
Deine Antwort
Vorschau umschalten

Folgen dieser Frage

Per E-Mail:

Wenn sie sich anmelden, kommen Sie für alle Updates hier in Frage

Per RSS:

Antworten

Antworten und Kommentare

Markdown-Grundlagen

  • *kursiv* oder _kursiv_
  • **Fett** oder __Fett__
  • Link:[Text](http://url.com/ "Titel")
  • Bild?![alt Text](/path/img.jpg "Titel")
  • nummerierte Liste: 1. Foo 2. Bar
  • zum Hinzufügen ein Zeilenumbruchs fügen Sie einfach zwei Leerzeichen an die Stelle an der die neue Linie sein soll.
  • grundlegende HTML-Tags werden ebenfalls unterstützt

Frage-Themen:

×22
×1

gestellte Frage: 09 Okt '14, 23:48

Frage wurde gesehen: 7,043 Mal

zuletzt geändert: 11 Okt '14, 08:57