I want to make the image arrangements as shown in the attachments. But I have no clue how to make such image arrangements. Please provide a solution to this problem.
- 53
2 Answers
Something like this?
\documentclass[tikz, border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0)--(10,0);
\foreach \i in {1,3,...,9}
\draw (\i,0) node[below]{0.\i} --++(90:2mm) node[above] {\includegraphics[width=1cm, height=1cm]{example-image-a}};
\foreach \i in {2,4,...,8}
\draw (\i,0) node[below]{0.\i} --++(90:2mm) +(0,1mm) [<-]--++(90:1.2cm) node[above] {\includegraphics[width=1cm, height=1cm]{example-image-a}};
\draw (10,0) node[below]{1.0} --++(90:2mm) +(0,1mm) [<-]--++(90:1.2cm) node[above] {\includegraphics[width=1cm, height=1cm]{example-image-a}};
\draw (0,0) node[below]{0.0}--++(90:2mm);
\end{tikzpicture}
\end{document}
- 136,588
Here is one way to do it using TeX's \ifodd test and \pgfmathprintnumber to print the graduations along the horizontal axis:
\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{calc, positioning}
\newcommand*{\myImgWidth}{1.3cm}% to avoid repeating a hardcoded value
\newlength{\myImgHeight}
\settoheight{\myImgHeight}{\includegraphics[width=\myImgWidth]{example-image-a}}
\begin{document}
\begin{tikzpicture}[x=10cm]
\foreach \X in {0, 1, ..., 10} {
\pgfmathsetmacro{\XF}{0.1*\X} % \XF is a float
\node[below] at (\XF,0) {%
\pgfkeys{/pgf/number format/.cd, fixed, precision=1, fixed zerofill}
\pgfmathprintnumber{\XF}};
\draw (\XF,0) -- (\XF,0.2); % the tick mark
\ifodd\X\relax
\node[above] at (\XF,0.2)
{\includegraphics[width=\myImgWidth]{example-image-a}};
\else
\draw[->]
% You may want to replace \myImgHeight with your max. image height
($(\XF,0.4) + (0,\myImgHeight)$)
node[above] {\includegraphics[width=\myImgWidth]{example-image-b}}
-- (\XF,0.25);
\fi
}
\draw (0,0) -- (1,0);
\end{tikzpicture}
\end{document}
Explanation of the \relax
The \relax following \ifodd\X is good practice here, because after \ifodd, TeX expands tokens until it has gathered a 〈number〉. In our case, it will not stop after expanding \X. Indeed, \X is not a \countdef token in the example (alias for a \count register—that would be a 〈number〉), it is a macro that expands to one or two decimal digits. According to the TeX grammar for 〈number〉, after these digits, TeX will continue expanding tokens until it finds an unexpandable token that is not a decimal digit (by grammar rule, if the first such token is a space token, it is swallowed). So, without the \relax (which is an unexpandable token), it would try to expand \node, which might cause trouble, depending on what the expansion yields. With \relax, we are sure that the 〈number〉 following \ifodd is given by the expansion of \X and nothing else. You can read here for more details on this subject.
- 24,283
- 1
- 32
- 55
-
thankyou so much...it works amazingly. – user187972 Dec 17 '19 at 13:28
-
Glad you liked it. I improved the answer a little bit. :-) – frougon Dec 17 '19 at 14:48
-
@user187972 Your unaccept will teach me to spend time for you. – frougon Dec 24 '19 at 13:14

