# How to construct a logic argument with colored hline with length under control?

How to construct a logic argument like this one?

I can construct it like this:

Latex of my argument:

\documentclass[10pt]{article}

\usepackage{newtxtext}
\usepackage{newtxmath}

\begin{document}
$\begin{array}{rl} & p \\ & p \to q \\ \cline{2-2} \therefore & q \end{array}$
\end{document}


There are three things I don't know how to do: 1) how to color the hline 2) how to control the length of the hline so it does not go beyond "p \to q"? 3) how to make the therefore symbol closer to q?

Basically, I need to construct one as close as possible to the first one.

-

You can use a simple tabular and colortbl:

\documentclass{article}
\usepackage{colortbl}
\usepackage{amsmath,amssymb}
\begin{document}
\begin{tabular}{c@{\,}l@{}}
& $p$ \\
\arrayrulecolor{blue}    & $p \to q$ \\\cline{2-2}
$\therefore$         & $q$ \\
\end{tabular}
\end{document}


You can change the color of the line using xcolor

\documentclass{article}
\usepackage{colortbl,xcolor}
\usepackage{amsmath,amssymb}
\begin{document}
\begin{tabular}{c@{\,}l@{}}
& $p$ \\
\arrayrulecolor{blue!60!green!70}    & $p \to q$ \\\cline{2-2}
$\therefore$         & $q$ \\
\end{tabular}
\end{document}


Same works with arrays also (since the MWE is given using arrays):

\documentclass[10pt]{article}
\usepackage{colortbl,xcolor}
\usepackage{newtxtext}
\usepackage{newtxmath}

\begin{document}
$\begin{array}{c@{\,}l@{}}\arrayrulecolor{blue!60!green!70} & p \\ & p \to q \\ \cline{2-2} \therefore & q \end{array}$
\end{document}

-
Works like a charm! This solves all my problems. Thanks! –  user21916 Nov 18 '12 at 14:04
what does @{\,} and @{} mean? –  user21916 Nov 18 '12 at 14:14
@user21916: @{} removes table column separation and @{\'} introduces a thin space. Without @{} columns will be separated by tabcolsep. –  Harish Kumar Nov 18 '12 at 14:50
Sorry read @{\'} as @{\,}. –  Harish Kumar Nov 18 '12 at 14:58
How to widen horizontal space between two columns in a table or array? e.g. three tabcolseps –  user21916 Nov 18 '12 at 15:59

I'd define an environment for this. Adjust the spacing (I used \enspace) and the color (here blue!50) to suit you.

\documentclass{article}
\usepackage{xcolor,colortbl,array,amssymb}

\newenvironment{deduction}
{\begin{tabular}{@{}>{$}c<{$}@{\enspace}>{$}l<{$}@{}}\arrayrulecolor{blue!50}}
{\end{tabular}}
\newcommand{\premise}[1]{&#1\\}
\newcommand{\conclusion}[1]{\cline{2-2}\therefore&#1}

\begin{document}
\begin{deduction}
\premise{p}
\premise{p\to q}
\conclusion{q}
\end{deduction}
\end{document}


-

Another possible solution:

\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath,amssymb}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node[yshift=-0.2ex]({#1}) {};}

\newcommand{\tikzhline}[3][1]{\tikz[overlay,remember picture]\draw[thick,cyan,shorten <=-{#1}pt,shorten >=-{#1}pt](#2.south)--(#3.south);}

\begin{document}
$\begin{array}{r@{\extracolsep{5pt}}l} & p\\ & \tikzmark{a}p\rightarrow q\tikzmark{b}\\ \tikzhline{a}{b} \therefore & q \end{array} \hspace*{0.5cm} \begin{array}{r@{\extracolsep{7pt}}l} & p\\ & \tikzmark{c}p\rightarrow q\tikzmark{d}\\ \tikzhline[6]{c}{d} \therefore & q \end{array}$
\end{document}


The result:

You will control the length by means of the optional parameter of \tikzhline.

-
While we are at it, I think we can draw the whole thing in TikZ and get away with a single run. –  percusse Nov 18 '12 at 17:47
@percusse: I see your point. In my mind, however, I considered a more general case: without knowing a priori the length of the statement, then the \tikzmark is more elastic. But, of course, if the target is always to underline a statement of type p \rightarrow q, then a simple TikZ-solution is the best. –  Claudio Fiandrino Nov 18 '12 at 18:56
See my answer for a primitive idea. Actually, this is what I have in mind for TikZ mark use. It looks like we can mark the position on the fly by system layer commands but the thesis is on the way :) First thesis, then hobby with matrix decomposition then this. –  percusse Nov 18 '12 at 19:21
@percusse: yes, it's interesting an simple. To be honest, I don't see the problem in compiling twice to get the result, because I'm used to compile several times when drawing something. But that's just a personal opinion. BTW: how's going the thesis? I've just printed mine today. –  Claudio Fiandrino Nov 19 '12 at 18:34
Wow. Congradulations!! I'm getting closer everyday but still needds a few months. –  percusse Nov 20 '12 at 10:01

If it is just the line that you need (assuming PDFLaTeX) the following is minimal on the requirements.

\documentclass[10pt]{article}
\usepackage{amsmath,newtxmath}
\begin{document}
\begin{align*}
&p                                                      \\
&p\pdfliteral{-10 -5 m 0.5 0 1 RG 0.5 w 25 -5 l S }\to q\\