2

I want to use package datatool for putting different names in one specified space of one image. Here for everyone's convenience I've formed a tikzpicture instead of image. Please see this minimal code.

\begin{filecontents}{abcd.csv}
a, b, c
Niranjan, Tambe, Vikas
Sushant, Devalekar, Shankar
Pranav, Patwardhan, Sachin
\end{filecontents}

\documentclass{article}
\usepackage{datatool}
\usepackage{tikz}
\DTLloaddb{abc}{abcd.csv}

\begin{document}
\DTLforeach{abc}{\firstname=a,\surname=b,\father=c}{\begin{tikzpicture}
\draw (-3,0) node[above]{\firstname{} \father{} \surname{} \\} -- (3,0);
\end{tikzpicture}\\
}
\end{document}

If we look at the output, I've got the names above the line. Now I want to do further things, which I don't know how to do. I want every name at the center of that line. Please note that optional arguments of node like [near end] are not useful for me right now as I want to implement all of this on an .jpg image. For now let's assume that the tikz code presented is frozen and we can't change it. It is here just for the sake of convenience and to avoid uploading a file. I want something which will allow me to specify some portion of the document and apply regular LaTeX commands on it. Please suggest me how to make LaTeX apply some commands like centering or center environment "only" on the specified portion of the document.

2
  • So you have a picture as a »background« and in the foreground you would like to print some words on it? If so, the eso-pic package is your friend. – Keks Dose Oct 21 '19 at 15:31
  • Yes, I know that package a bit, but let's say on the left corner of that image I have a 1 cm line (like in the question). I want to specify that much portion in the code and with datatool package, add many names on that line, but keeping in mind all the names should be centrally alligned. (I hope I am not confusing :P) Is eso-pic still helpful for this kind of specifications? – Niranjan Oct 21 '19 at 15:35
2
+50

I'm not sure if I understand the question. But you can set coordinates in a tikzpicture and use them later to place your text:

\begin{filecontents}{abcd.csv}
a, b, c
Niranjan, Tambe, Vikas
Sushant, Devalekar, Shankar
Pranav, Patwardhan, Sachin
\end{filecontents}

\documentclass{article}
\usepackage{datatool}
\usepackage{tikz}
\usetikzlibrary{calc}
\DTLloaddb{abc}{abcd.csv}

\begin{document}
\begin{tikzpicture}[remember picture]
\draw (-3,0)coordinate(a1)  -- (3,0)coordinate(b1);
\draw (-2,1)coordinate(a2)  -- (4,1)coordinate(b2);
\draw (-1,2)coordinate(a3)  -- (4,2)coordinate(b3);
\end{tikzpicture}

\DTLforeach{abc}{\firstname=a,\surname=b,\father=c}{%
 \begin{tikzpicture}[remember picture, overlay]
  \node[above] at ($(a\number\value{DTLrowi})!0.5!(b\number\value{DTLrowi})$)
   {\firstname{} \father{} \surname{}};
 \end{tikzpicture}}
\end{document}

enter image description here

You can place with tikz an (invisible) grid over the images and then use the coordinates like in my example to add the text. See e.g. Simplest way to overlay a text + rectangle label an image? and Drawing on an image with TikZ.

4
  • Thanks Urlike for your effort, but sorry. This is not what I wanted. I am looking for a tool which enables me to specify some space over an image. I've mentioned that tikz commands do not seem to be helpful here. The tikz-code presented by me was an example code, to avoid image uploads. This is not a tikz question. Let me explain my question again. eg. If we use WYSIWYG image editing tools like 'inkscape', we can insert a text box wherever we want and align (l/c/r) the text inside it. With the help of co-ordinates can we achieve this in LaTeX? Placing alignment-friendly text-boxes anywhere. – Niranjan Nov 4 '19 at 7:43
  • Please use my tikz-code as an uneditable image and try to insert some positioning commands. – Niranjan Nov 4 '19 at 7:52
  • You can place with tikz an (invisible) grid over the images and then use the coordinates like in my answer to add the text. See e.g. tex.stackexchange.com/questions/9559/… and tex.stackexchange.com/questions/30427/… – Ulrike Fischer Nov 4 '19 at 7:54
  • Oh if that's the case, it is exactly what I'm searching for, but unfortunately I didn't understand those commands. The answers referred by you cleared the doubts. Thanks. +1 :) – Niranjan Nov 4 '19 at 8:16

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.