5

I hope I can put this the right way:

What I want from LaTeX is for example:

Example

a+b*c=  
| a=1+2  
| b=g*2+3  
||g=2b  
|||g=3  
|c= 4+d  
||d=3  

and the | should be connected. Like a normal list with tabulator spaces.

Or if there is another way to show an equation as some kind of graphic that is connected.

What I found was xypic but this is not really what I'm looking for.

I could do it with a table, with the first column being connected and in there's a big vertical line, ….

Do you know something? Do you have any tip?

This is not just for pure maths.

1
  • I have revised the solution to show how math axis can be placed in the middle, for either an odd number or an even number of rows being stacked. – Steven B. Segletes Jul 8 '13 at 19:39
4

The spacing between the rules is settable, in the definition of \lbar, currently set to 0.7ex. Below, I show it with either the math axis on the bottom line, the top line, or in the middle (odd # rows, then even # rows), respectively.

The keys are \Longstack which stacks above the baseline with uniform inter-row spacing, \Longunderstack which stacks from the baseline downward, with uniform interrow spacing, and (for the last example) \stackanchor which (for \stacktype "L")moves the aggregate baseline halfway between the baseline of the upper and lower items.

\documentclass{article}
\usepackage{stackengine}
\def\lbar{%
  \protect\rule[-.3\baselineskip]{.1ex}{\baselineskip}%
  \protect\rule{.7ex}{0ex}%
}
\begin{document}
\[
x = 
\Longstack[l]{%
{$a+b*c$}
{\lbar $a = 1 + 2$}
{\lbar $b = g*2 + 3$}
{\lbar\lbar $g = 2b$}
{\lbar\lbar\lbar $g = 3$}
{\lbar $c = 4 + d$}
{\lbar $d = 3$}%
}
\]

\[
x = 
\Longunderstack[l]{%
{$a+b*c$}
{\lbar $a = 1 + 2$}
{\lbar $b = g*2 + 3$}
{\lbar\lbar $g = 2b$}
{\lbar\lbar\lbar $g = 3$}
{\lbar $c = 4 + d$}
{\lbar $d = 3$}%
}
\]

\[
x=
\savestack{\upperstack}{\Longstack[l]{%
{$a+b*c$}
{\lbar $a = 1 + 2$}
{\lbar $b = g*2 + 3$}
{\lbar\lbar $g = 2b$}%
}}
\Longunderstack[l]{%
{\upperstack}
{\lbar\lbar\lbar $g = 3$}
{\lbar $c = 4 + d$}
{\lbar $d = 3$}%
}
\]

\[
x=
\savestack{\upperstack}{\Longstack[l]{%
{$a+b*c$}
{\lbar $a = 1 + 2$}
{\lbar $b = g*2 + 3$}%
}}
\savestack{\lowerstack}{\Longunderstack[l]{%
{\lbar\lbar $g = 2b$}
{\lbar\lbar\lbar $g = 3$}
{\lbar $c = 4 + d$}%
}}
\def\stackalignment{l}
\def\stacktype{L}
\stackanchor{\upperstack}{\lowerstack}
\]
\end{document}

enter image description here

5
  • Great possibility. But I don't get it working. I have MikTex 2.ß and texmaker running. I always get: ! LaTeX Error: File `readarray.sty' not found. What am I doing wrong? – Tim Kaluza Jul 8 '13 at 18:19
  • @TimKaluza Your installation does not have the readarray package. It can be found at ctan.org/pkg/readarray. You can download the sty file into your current directory to get it working, but in the longer run, you ought to place it into your "local repository" (and update the FileName DataBase [FNDB]). That repository should be found at, by default, C:\Users\[your user name]\AppData\Roaming\MiKTeX\2.9\tex\latex – Steven B. Segletes Jul 8 '13 at 18:23
  • @TimKaluza No problem. Glad to help. V1 of readarray only came out in late March. We're up to V1.2 currently. – Steven B. Segletes Jul 8 '13 at 18:32
  • But you can't put the whole equation in math mode like [..]\ in John Wickerson's solution, do you? I prefer still this as the solution because of being a bit easier to write as the other one. – Tim Kaluza Jul 8 '13 at 18:48
  • @TimKaluza Yes, it can be issued in math mode. The question is where do you want the math axis? I'll revise my solution to demonstrate. – Steven B. Segletes Jul 8 '13 at 18:55
4

Here's another possibility:

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{align}
    a&+b*c = \\
    &\left|\begin{aligned}
        a&=1+2\\
        b&=g*2+3\\
        &\left|\begin{aligned}
            g&=2b\\
            &\left|\begin{aligned}
                g=3
            \end{aligned}\right.\\
        \end{aligned}\right.\\
        c&= 4+d\\
        &\left|\begin{aligned}
            d=3
        \end{aligned}\right.\\
    \end{aligned}\right.
\end{align}
\end{document}

enter image description here

3

Here's one possibility, obtained by modifying an old answer by Steven Segletes about how to format an email conversation (https://tex.stackexchange.com/a/121987/25356).

\documentclass{article}

\usepackage{scalerel}
\global\newcounter{embedlevel}
\global\newlength\embedspace
\embedspace=3ex
\setcounter{embedlevel}{1}

\newcommand\embed[1]{%
  \stepcounter{embedlevel}%
  \stretchrel{\rule{0.2ex}{1ex}}{\hspace{\embedspace}\parbox{%
    \textwidth-\value{embedlevel}\embedspace}{%
    \rule{0ex}{2ex}$#1$\rule[-1.3ex]{0ex}{1.3ex}%
  }}%
  \vspace{.5ex}%
  \addtocounter{embedlevel}{-1}%
}

\parindent=0pt

\begin{document}
\[
\begin{array}{l}
a+b*c=\\
\embed{%
  a=1+2 \\ 
  b=g*2+3\\
  \embed{%
    g=2b\\
    \embed{%
    g=3
    }%
  }\\
  c= 4+d\\
  \embed{%
    d=3
  }%
}
\end{array}
\]

\end{document} 

enter image description here

0

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.