I want to indent the next line by an exactly specified position
Most TeX compilers provide the feature \pdfsavepos
that allows to record the position on the shipout page. It was introduced in pdfTeX and is nowadays available in pdfTeX, both modes DVI and PDF, XeTeX, and LuaTeX.
Because the position is not known, before the page is output, some kind of reference system is needed. Package zref-savepos
of project zref
provides an interface to the \pdfsavepos
feature.
\documentclass{article}
\usepackage{zref-savepos}
\makeatletter
% \zsaveposx is defined since 2011/12/05 v2.23 of zref-savepos
\@ifundefined{zsaveposx}{\let\zsaveposx\zsavepos}{}
\makeatother
\newcounter{hposcnt}
\renewcommand*{\thehposcnt}{hpos\number\value{hposcnt}}
\newcommand*{\SP}{% set position
\stepcounter{hposcnt}%
\zsaveposx{\thehposcnt s}%
}
\makeatletter
\newcommand*{\UP}{% use previous position
\zsaveposx{\thehposcnt u}%
\zref@refused{\thehposcnt s}%
\zref@refused{\thehposcnt u}%
\kern\zposx{\thehposcnt s}sp\relax
\kern-\zposx{\thehposcnt u}sp\relax
}
\makeatother
\begin{document}
This \SP is the first line\\
\UP One more \SP line\\
\UP And another.
\end{document}
Some remarks:
The label names are automatically chosen via the help of a counter. That makes the usage easier, because the user don't need to invent unique label names.
The internal position data are integer numbers with implicit unit
sp
.\zref@refused
marks the reference as used to allow LaTeX the notification for undefined references.
Text mode
You could use the tabbing
environment:
\documentclass{article}
\newenvironment{Tabbing}{% see http://tex.stackexchange.com/a/16389/16595
\vspace{-\baselineskip}%
\setlength{\topsep}{0pt}\setlength{\partopsep}{0pt}\tabbing%
}{\endtabbing}
\begin{document}
\noindent This is a line before the \verb|Tabbing| environment.
\begin{Tabbing}
This \= One more \=\kill\\
This \> is the first line. \\
\> One more line. \\
\> \>And another.
\end{Tabbing}
This is a line after the \verb|Tabbing| environment.
\end{document}
Output:
Math mode
For math I'd suggest the alignat
environment:
\begin{alignat*}{2}
\textrm{This } & \rlap{is the first line.} & & \\
& \textrm{One more } & &\textrm{line.} \\
& & &\textrm{And another.}
\end{alignat*}
Output:
Use \(\displaystyle <math> \)
inside \rlap
to get back to math mode.
For completeness, \phantom{<stuff>}
is also a possibility:
\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\setlength{\parindent}{0pt}% For this example.
\begin{document}
\lipsum[2]% Some dummy text.
This is the first line. \par
\leavevmode\phantom{This }One more line. \par
\leavevmode\phantom{This One more }And another.
\lipsum[2]% Some dummy text.
\end{document}
\leavevmode
is required if the paragraph starts with \phantom
.