7

I am creating a question type for an exam in which three terms have to be assigned by connecting them with a line. This is to be drawn through the multirow of the table. The anchor points should always be in the middle at the respective edge of the cell. Depending on the question, individual cells can also be multi-row. For the sample solution of the exam I would like to connect this via latex. Can someone help me how to draw lines across the multirows?

\documentclass{standalone}
\usepackage{array}
\usepackage{multirow}
\begin{document}
\begin{tabular}{|>{\raggedright}p{3cm}|>{\raggedright}p{2cm}|>{\raggedright}p{3cm}|>{\raggedright}p{2cm}|>{\raggedright}p{3cm}|}
\hline 
Word bla blab bla bla bla bla bla & \multirow{3}{2cm}{} & WYSIWYM & \multirow{3}{2cm}{} & .lyx\\
\cline{1-1} \cline{3-3} \cline{5-5} 
\LaTeX &  & WYSIWYG &  & .docx bla bla bla bla bla bla bla\\
\cline{1-1} \cline{3-3} \cline{5-5} 
Lyx &  & WYSIWYAF &  & .tex\\
\hline 
\end{tabular}
\end{document}

enter image description here

1 Answer 1

6

With {NiceTabular} of nicematrix. That environment is similar to the classical environment {tabular} (of array) but creates also PGF/Tikz nodes under the cells, rows and columns. You can use these nodes to draw with Tikz whatever rule you want.

\documentclass{article}
\usepackage{geometry}
\usepackage{nicematrix,tikz}

\begin{document}

\begin{NiceTabular}{p[l]{3cm}p[l]{2cm}p[l]{3cm}p[l]{2cm}p[l]{3cm}}[hvlines]
Word bla blab bla bla bla bla bla & \Block{3-1}{} & WYSIWYM & \Block{3-1}{} & .lyx\\
\LaTeX &  & WYSIWYG &  & .docx bla bla bla bla bla bla bla\\
Lyx &  & WYSIWYAF &  & .tex\\
\CodeAfter 
  \tikz 
    \draw [red] (1.5-|2) -- (2.5-|3) 
                (2.5-|2) -- (3.5-|3) 
                (3.5-|2) -- (1.5-|3) 
                (1.5-|4) -- (1.5-|5) 
                (2.5-|4) -- (2.5-|5) 
                (3.5-|4) -- (3.5-|5) ;
\end{NiceTabular}

\end{document}

You need several compilations (because of the PGF/Tikz nodes).

Output of the above code

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.