1

I would like to place a series of lines using the picture environment in latex but I can to placement of those lines to be relatively placed not absolutely place; i.e. I want to have defined coordinates that I can build off of.

Basic example of absolute placement:

\setlength{\unitlength}{0.75mm}
\begin{picture}(60,40)
\put(20,20){\line(5,2){1}}
\put(30,20){\line(5,3){1}}
\end{picture}

Basic example of relative placement (what I would like):

xc=20

\setlength{\unitlength}{0.75mm}
\begin{picture}(60,40)
\put(xc,20){\line(5,2){1}}
\put(xc+10,20){\line(5,3){1}}
\end{picture}

Does anyone have any suggestions?

CTMW
  • 13

2 Answers2

0

This will allow quite extensive syntax but might be overkill.

I am assuming only integer calculations are needed (hence the ii) as in \numexpr. Use / for usual rounded integer division. Use // for floored division and /: for associated modulo. You can also use comma separated expressions (but \put must see the comma first, sadly, it can not arise from expansion alone thus I can't demonstrate it in this example). The syntax admits powers, factorials, ...

\documentclass{article}

\usepackage{xintexpr}
\newcommand\IntExpr[1]{\xinttheiiexpr #1\relax}
\begin{document}

\xintdefiivar xc:=20;%

\setlength{\unitlength}{0.75mm}

\begin{picture}(60,40)
\put(\IntExpr{xc},20){\line(5,2){10}}
\put(\IntExpr{xc+10},20){\line(5,3){10}}
\end{picture}
\end{document}

enter image description here

  • in languages makeing the : or ;active like babel+frenchb, one needs to turn this off for \xintdefiivar, or alternative is to define a wrapper for it in preamble where the : and ; still have their usual catcodes. –  Mar 20 '18 at 20:11
0

enter image description here

\documentclass{article}

\begin{document}

\newcommand\xc{20}
\setlength{\unitlength}{1mm}%.75mm is rather small

\fbox{\begin{picture}(60,40)
\put(\xc,20){\line(5,2){10}}% 1 mm is too small
\put(\numexpr\xc+10\relax,20){\line(5,3){10}}
\end{picture}}

\end{document}
David Carlisle
  • 757,742