# How to draw lines between letters

I want to draw a line in text just as in this picture. No colours needed, everything black on white. The relative positions of the letters need to stay the same - no shifting allowed.

I've tried a solution using tabular but since there doesn't seem to be a way to dynamically add/remove vertical lines between cells I had to give up.

• And one minute after posting I found the solution. I can dynamically add vertical lines using the multicolumn tag. May 30 '16 at 17:20
• Welcome to TeX.SE. Beside solution with table also are other solution, for example drawing with pstrick or tikz. May 30 '16 at 17:31
• It would be great if you shared the answer you found. May 30 '16 at 17:36
• Adding vertical lines adds shifting (of at least line thickness). May 30 '16 at 19:17
• You can also use tikzmark to do this. This allows you to separate the text and the drawing. May 30 '16 at 20:14

Some juggling with tabular parameters:

\documentclass{article}
\usepackage{array}

\newcommand{\lb}[1]{\makebox[1em]{#1}}

\begin{document}

\begingroup
\setlength{\tabcolsep}{0pt}
\setlength{\extrarowheight}{10pt}
\renewcommand{\arraystretch}{0.5}
\begin{tabular}{*{6}{c}}
\lb{G} & \multicolumn{1}{|c}{\lb{A}} & \lb{A} & \lb{T} & \lb{T} & \lb{C} \\
\cline{2-5}
\lb{C} & \lb{T} & \lb{T} & \lb{A} & \multicolumn{1}{c|}{\lb{A}} & \lb{G}
\end{tabular}
\endgroup

\end{document}


Here is a solution with pstricks: it consists in making each letter a box with 12 nodes, and connecting the relevant nodes with the \ncangle command:

\documentclass[12pt, x11names]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{microtype}
\usepackage{pst-node}
\usepackage{auto-pst-pdf}

\begin{document}

\begin{postscript}
\sffamily\Large
G\psDefBoxNodes{T}{\,A}\,A\,T\,T\,C \\
C\,T\,T\,A\,A\,\psDefBoxNodes{B}{G}
\ncangle[angleA=-90, angleB=90, armB=1.75ex, linewidth=1.2pt, linejoin=1, linecolor=Green4!80]{T:tl}{B:bl}
\end{postscript}

\end{document}


And solution with TikZ based on use of TikZ library matrix:

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{matrix}

\begin{document}
\begin{tikzpicture}
\matrix (m) [matrix of math nodes,inner xsep=1pt,inner ysep=2pt,row sep=0pt]
{
G   &   A   &   A   &   T   &   T   &   C   \\
C   &   T   &   T   &   A   &   A   &   G   \\
};
\draw[thick,green]
([yshift=-2pt] m-1-1.north east) |- (m-2-5.north east) -- ([yshift=+2pt]m-2-5.south east);
\end{tikzpicture}
\end{document}
`

• Don't use JPG for diagrams. May 30 '16 at 23:10
• @AndreasRejbrand, just to know: why not? May 31 '16 at 0:43
• JPG is designed to be used for photographs. It uses a lossy compression which is barely noticeable in photographs, but will produce obvious artefacts in non-photographic images like diagrams and computer screenshots with exact lines and solid-colour regions. PNG is designed for this kind of graphics, is very efficient with solid-colour regions and uses no lossy compression. See english.rejbrand.se/rejbrand/msword.asp#raster-graphics for more information. May 31 '16 at 11:55
• At least to me, the JPG version of your image looks annoyingly distorted, especially at the top of the green line. See this non-interpolated magnification: privat.rejbrand.se/tex-dna-jpg.png. For a comparison, have a look at Bernard's PNG: privat.rejbrand.se/tex-dna-png.png May 31 '16 at 13:46
• Do you have better suggestion hot to generate picture for showing here? Please, advice me. Technique should be simple and fast. This picture, taken from screen with Snipping Tool, is only approximation -- poor as you stated -- of real picture obtained by MWE in pdf format. May 31 '16 at 13:55