0

i use datatool and connect Text and Image together. See attached image.

If this text (Text A or Text B) is long, then split 2 lines.

Minimal Working code:

\RequirePackage{filecontents}
\begin{filecontents*}{file.tex}
 No,TextA,TextB
 1,a1 a1a1 a1a1a1 a1a1,b1 b1 b1
 2, ,b22 b2b2 b2b2b2 b2b2
 3,a3 a3 a3, b3b3
 4,,
 5,a5 a5a5,


\end{filecontents*}

\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage{filecontents}
\usepackage{datatool}
\usepackage{wrapfig}
\usepackage{xparse}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{tcolorbox}
\tcbuselibrary{poster}

\usepackage{bbding}
\usepackage{pifont}
\usepackage{enumitem, setspace}
 \tcbset{colframe=blue!75!black,colback=white}


 \DTLloaddb{file}{file.tex}

 \begin{document}

 \DTLforeach*
 {file}% Database
 {\No=No,\TextA=TextA,\TextB=TextB}
 {%
 \begin{tcbposter}[
  poster = {
    columns=1,
    rows=1,
    spacing=3mm,
    height=14cm,
    width=12cm,
  },
]
%Box A

\posterbox[colframe=red,width=7cm,height=6cm]{name=A,column=1}{

\begin{enumerate}[leftmargin =-1em]
\item[]  \raisebox{1ex-0.5\height}{\includegraphics[width=3cm]{example-image-a}}  \TextA \hfill xxx
\item[]  \raisebox{1ex-0.5\height}{\includegraphics[width=3cm]{example-image-b}}  \TextB \hfill yyy
\end{enumerate}
}
\end{tcbposter}
\newpage
}

\end{document}

enter image description here

Thank for help

latexforti
  • 2,091

2 Answers2

1

This can be achieved with parbox as long as you are aware it cant split long words, your modified mwe does not compile as there are conflicting raisebox entries, so I have separated them for this amended answer

enter image description here

\RequirePackage{filecontents}
\begin{filecontents*}{file.tex}
 No,TextA,TextB
 1,a1 a1a1 a1a1a1 a1a1,b1 b1 b1 b1
 2, ,b22 b2b2 b2b2b2 b2b2
 3,a3 a3 a3, b3b3
 4,,
 5,a5 a5a5,


\end{filecontents*}

\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage{filecontents}
\usepackage{datatool}
\usepackage{wrapfig}
\usepackage{xparse}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{tcolorbox}
\tcbuselibrary{poster}

\usepackage{bbding}
\usepackage{pifont}
\usepackage{enumitem, setspace}
 \tcbset{colframe=blue!75!black,colback=white}


 \DTLloaddb{file}{file.tex}

 \begin{document}

 \DTLforeach*
 {file}% Database
 {\No=No,\TextA=TextA,\TextB=TextB}
 {%
 \begin{tcbposter}[
  poster = {
    columns=1,
    rows=1,
    spacing=3mm,
    height=14cm,
    width=12cm,
  },
]
%Box A

\posterbox[colframe=red,width=7cm,height=6cm]{name=A,column=1}{

\begin{enumerate}[leftmargin =-1em]
\item[]  \raisebox{-0.5\height}{\includegraphics[width=3cm]{example-image-a}}\raisebox{-1ex}{~\parbox{3.5cm}{\raggedright \TextA \hfill ~ xxxxx xxxxx xxxxxxx}}
\item[]  \raisebox{-0.5\height}{\includegraphics[width=3cm]{example-image-b}}\raisebox{-3pt}{~\parbox{3.5cm}{\raggedright \TextB \hfill ~ yyyyyyyy yyyyyyyyyyyyyyyyyyyyy}}
\end{enumerate}
}
\end{tcbposter}
\newpage
}

\end{document}
  • thank for your help. It's ok. But if i use raisebox{1ex-.5\height} instead \raisebox{-0.5\height) then break. Do you solution for raisebox{1ex-.5\height} thanks – latexforti May 18 '19 at 09:02
  • 1
    Updated to include 2nd part raisebox + - ex or pt etc –  May 18 '19 at 20:22
1

An alternative is use of array, booktabs and adjustbox packages:

\begin{filecontents*}{file.tex}
No,TextA,TextB
1,a1 a1a1 a1a1a1 a1a1 aa aa aaaaaaaaaaa,b1 b1 b1 b1 b1 b1b1 b1 b1
2, ,b22 b2b2 b2b2b2 b2b2
3,a3 a3 a3, b3b3
4,,
5,a5 a5a5,
\end{filecontents*}

\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage[export]{adjustbox}
\usepackage{filecontents}
\usepackage{datatool}
\usepackage{tcolorbox}
\tcbuselibrary{poster}
\tcbset{colframe=blue!75!black,colback=white}
\usepackage{array, booktabs}

\DTLloaddb{file}{file.tex}

\begin{document}

\DTLforeach*
{file}% Database
{\No=No,\TextA=TextA,\TextB=TextB}
{%
\begin{tcbposter}[
poster = {
columns=1,
rows=1,
spacing=3mm,
height=14cm,
width=12cm,
},
]
%Box A
\posterbox[colframe=red,width=7cm,height=6cm]{name=A,column=1}%
{
\setkeys{Gin}{width=\linewidth}
\begin{tabular*}{\linewidth}{@{} *{2}{p{\dimexpr0.5\linewidth-2\tabcolsep}} @{}}
\hline
\includegraphics[valign=t]{example-image-a}
&   \centering\arraybackslash
    \TextA\ xxxx xx xxxxx              \\
\addlinespace
\includegraphics[valign=t]{example-image-b}
&   \raggedright\arraybackslash
    \TextB\   yyyy yyy yyyyyyyyyyyyyy
\end{tabular*}
}
\end{tcbposter}
\newline
}
\end{document}

enter image description here

Note, if long words are not natural, i.e. haven't \hyphenation points, that thew will spill out of table and \posterbox too..

Zarko
  • 296,517
  • Sorry but what is "\hyphenation" in code? – latexforti May 18 '19 at 16:27
  • 1
    for the (almost) each language is defined option for this language for babel option. It contain patterns for hyphenate of words and other language specific definitions (as names of captions labels, etc). However, this patterns cannot hyphenate words like yyyyyyyyyyyyyyyyyyyyy ... – Zarko May 18 '19 at 17:33