0

Zref does calculate the coordinate of north west of P1 (= baseline of "some text"), which in my case is approx (50mm, 274mm)

enter image description here

so if i make "uuuuuu" in Textblock with the same coordinates, it also puts "uuuuu" in north west. Then the baseline is not the same. The result seems like it shiftet.

My simple question: how can i force zref and textblock operate with the baseline and not north west?

\documentclass[12pt,oneside,german]{article}  
\usepackage[T1]{fontenc} 
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage[paperwidth=210 mm,paperheight=297 mm,left=50mm,top=20mm]{geometry} 
\usepackage[absolute,overlay]{textpos} 
\usepackage{zref-abspos}  
\usepackage{tcolorbox}  
%\tcbuselibrary{skins,breakable}


\topskip=0pt  
\setlength{\parindent}{0pt} % = global \noindent 
\renewcommand{\baselinestretch}{1.3} 

\newcommand{\myfunction}[1]{%
\zsavepos{P1}% Store the current position as #1
#1%
}

\makeatletter
\newcommand\dimtomm[1]{%
\strip@pt\dimexpr 0.351459804\dimexpr#1\relax\relax 
}
\makeatother

\textblockorigin{0mm}{297mm}
\begin{document}
some text

\myfunction{P1} 

\vspace*{5mm}
The coordinate of P1 is: (\dimtomm{\the\dimexpr \zposx{P1}sp \relax} mm,\dimtomm{\the\dimexpr \zposy{P1}sp \relax} mm)

\begin{textblock*}{\the\textwidth}(49.9994mm,-274.40306mm)%
    \textcolor{red}{uuuuuuu}
\end{textblock*} 

 

\end{document}
1

I added a \noindent before \zsavepos{P1} inside the definition of \myfunction so as to save the position P1 after starting a new paragraph (which was done by \myfunction's first argument in your code, and caused the saved position to be above the baseline of the typeset text corresponding to #1).

I also added [0,1] after \begin{textblock*}{\the\textwidth} in order to vertically shift the block continaing uuuuuuu by its height (otherwise, its upper left corner would be at P1's baseline, not its lower left one).

\documentclass{article}
\usepackage{xcolor}
\usepackage[paperwidth=210 mm,paperheight=297 mm,left=50mm,top=20mm]{geometry}
\usepackage[absolute,overlay]{textpos}
\usepackage[savepos]{zref}

\topskip=0pt
\setlength{\parindent}{0pt} % = global \noindent
\renewcommand{\baselinestretch}{1.3}

\newcommand{\myfunction}[1]{%
  \noindent\zsavepos{P1}% Store the current position as #1
  #1%
}

\textblockorigin{0mm}{297mm}

\begin{document}
some text

\myfunction{P1}

\begin{textblock*}{\textwidth}[0,1](\zposx{P1}sp,-\zposy{P1}sp)%
  \textcolor{red}{uuuuuuu}
\end{textblock*}

% With multiline text
\begin{textblock*}{\textwidth}[0,1](\zposx{P1}sp,-\zposy{P1}sp)%
  \begin{minipage}[t]{\textwidth}
  \color{blue}... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
  ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
  ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
  ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
  \end{minipage}
\end{textblock*}

\end{document}

enter image description here

4
  • Thanks! I also got it few minutes ago :) The last thing is to put around uuuuu a parbox as follows: \parbox[t]{\the\textwidth}{\textcolor{red}{uuuuuuu}} Then the text "uuuuu" starts above the baseline! Maybe u can edit it. Also u can put [0,1], [0,0], [1,1], [1,0] (or in between) to textblock, so that the alignment changes. U can put e.g. [0,1] as {\the\textwidth}[0,1](\zposx{P1}sp,-\zposy{P1}sp) Feb 8 at 16:03
  • Ah, I had not quite understood what you wanted to achieve the first time. I added a [0,1] after \begin{textblock*}{\the\textwidth}; I believe this is what you want.
    – frougon
    Feb 8 at 16:13
  • perfect! But if "uuuu" is more then 1 line, then it gets also shiftet. This is why i used parbox. Just try a long text instead of "uuuu" and u will see... Feb 8 at 16:50
  • All right, I've added an example with multiline text using \begin{minipage}[t]{\textwidth} ... \end{minipage}.
    – frougon
    Feb 8 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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