0

I'm very new to LaTeX would like to ask some advice on how to position elements inside a fixed size box. Fox each element I know the X/Y relative position to a box corner.

When I try to use spacing to position the text inside the box, I see some movement on the horizontal, but no vertical movement.

My aim is to print multiple of those boxes, which all have the same layout (and will include not only text, but also images)

Is there a way in LaTeX that I can position elements by a known position?

\fbox{\begin{minipage}[c][5.2cm][l]{509pt}%
%
\vspace{1.5cm}\hspace{1.0cm}Hello World 1 %
\vspace{1.5cm}\hspace{2.0cm}Hello World 2 %
\vspace{2.5cm}\hspace{1.0cm}Hello World 3 %
\vspace{2.5cm}\hspace{2.0cm}Hello World 4 %
\hfill\end{minipage}}\

This is the output the code generates

This is how the output looks

I'm trying to get an output like this

wanted output

576i
  • 113
  • Welcome to TeX.SX!. To get text in a new line, you need to use the command \\ that has an optional argument to insert vertical space. However, I think a table might be a better option for such things. – Imran May 04 '22 at 17:06
  • @imram - thanks, the question is about how to position elements at relative coordinates, not just a new line (the real world code would have 10-20 of them, a logo and a graphic as well). Forcing them in a table structure would be horribly complicated, so I'm hoping that there's some way of doing this inside of a fbox. – 576i May 04 '22 at 17:14
  • @David - this looks very promising. The only reason why my example looks like a table is because it's a minimal example. I'll give it a try and upvote – 576i May 04 '22 at 18:01

1 Answers1

3

enter image description here

Picture mode isn't just for technical drawing

\documentclass{article}

\begin{document}

\fbox{\begin{picture}(10cm,7cm) \put(2cm,1cm){this} \put(8cm,5cm){that} \put(5cm,6cm){3rd} \end{picture}} \end{document}

David Carlisle
  • 757,742
  • if you get errors from the units, you have an old latex, and add \usepackage{picture} to allow units or just use values without units (which will be pt) – David Carlisle May 04 '22 at 18:04
  • This is very promising. At the moment I have a the problem that the text breaks out of the minipage inside the fbox (which is fixed in size) but at least there's placement action. – 576i May 04 '22 at 18:12
  • @576i you don't need a minipage at all. Just make the picture mode the size you want (I did 10cm by 7cm here) – David Carlisle May 04 '22 at 18:17
  • That works. Great. – 576i May 04 '22 at 18:23
  • Thanks again for suggesting this, that was really helpful. I played a bit more with this and it works fine with a combination of images, barcodes and text. – 576i May 04 '22 at 19:29
  • 1
    @576i yes I guess your end result is more like this https://tex.stackexchange.com/a/213293/1090 – David Carlisle May 04 '22 at 19:48