Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Edit. Some comments might be outdated.

I would like to do the following:

enter image description here

The blue parts should be treated as normal paragraph text, with normal automatic hyphenation. The green part is what you typically get from an align* environment. As you see in the figure, I would like to revisit the same alignment after a kind of \intertext paragraph. I have tried with the tabbing environment but it doesn't support making tabs towards the end of wrapped lines. tabularx and other table environments makes it problematic to let TeX typeset the first blue paragraph as a whole, as the third line (with blue and green) is separated from the first two blue lines. Also, it is difficult to let some lines of the green region overlap the blue region on other lines if the regions are put in different columns.

Below is the code from my original post. From the code, it seems that I have succeeded, but I would like to do it with more elegant code.

\documentclass[10pt,twoside,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[norsk]{babel}
\usepackage{lmodern}
\usepackage[lmargin=5cm,rmargin=186.3661pt,tmargin=5cm,bmargin=5cm]{geometry}
\usepackage[table]{xcolor}
\definecolor{red}{HTML}{dd0000}

\begin{document}

\setlength{\parindent}{0mm}

\makebox[\linewidth][s]{Hvis en addend minker med 1, så minker summen med 1:}
\begin{tabular}{@{}l@{ }r@{\,\,}l@{\,\,}l@{}p{4.822cm}}
  Det betyr at\hspace{-3.5mm} & $5+2$ & $=$ & $7$, &\\
                  & $5+1$ & $=$ & $6$, &\\
                  & $5+0$ & $=$ & $5$, &\\
                  & $5+(-1)$ & $=$ & $4$, &\\
                  & $5+(-2)$ & $=$ & ${\color{red}3}$, osv., & \hfill så å legge til et negativt tall
\end{tabular}
\makebox[\linewidth][s]{er det samme som å trekke fra samme tall med motsatt fortegn:}
\begin{tabular}{@{}l@{ }r@{\,\,}l@{\,\,}l@{}p{3.841cm}}
\hspace{15.695mm}   & $5+(-2)$ & $=$ & $5-(+2)=5-2={\color{red}3}$. &\\
\end{tabular}

\end{document}

enter image description here

share|improve this question
    
Welcome to TeX.SX. –  Claudio Fiandrino Mar 1 '13 at 13:11
add comment

1 Answer

You'd tagged the question as tabularx, and I think all you need to do if I understand the question correctly is use that package

enter image description here

\documentclass[10pt,twoside,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[norsk]{babel}
\usepackage{lmodern}
\usepackage[lmargin=5cm,rmargin=186.3661pt,tmargin=5cm,bmargin=5cm]{geometry}
\usepackage[table]{xcolor}
\usepackage{tabularx}
\definecolor{red}{HTML}{dd0000}

\begin{document}

\setlength{\parindent}{0mm}

\makebox[\linewidth][s]{Hvis en addend minker med 1, så minker summen med 1:}

\begin{tabularx}{\linewidth}{@{}l@{ }r@{\,\,}l@{\,\,}l@{}X@{}}
  Det betyr at\hspace{-3.5mm} & $5+2$ & $=$ & $7$, &\\
                  & $5+1$ & $=$ & $6$, &\\
                  & $5+0$ & $=$ & $5$, &\\
                  & $5+(-1)$ & $=$ & $4$, &\\
                  & $5+(-2)$ & $=$ & ${\color{red}3}$, osv., & \hfill så å legge til et negativt tall
\end{tabularx}

\makebox[\linewidth][s]{er det samme som å trekke fra samme tall med motsatt fortegn:}

\begin{tabularx}{\linewidth}{@{}l@{ }r@{\,\,}l@{\,\,}l@{}X@{}}
\hspace{15.695mm}   & $5+(-2)$ & $=$ & $5-(+2)=5-2={\color{red}3}$. &\\
\end{tabularx}

\end{document}

Or as discussed in comments all in one table

enter image description here

\documentclass[10pt,twoside,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[norsk]{babel}
\usepackage{lmodern}
\usepackage[lmargin=5cm,rmargin=186.3661pt,tmargin=5cm,bmargin=5cm]{geometry}
\usepackage[table]{xcolor}
\usepackage{tabularx}
\definecolor{red}{HTML}{dd0000}

\begin{document}

\setlength{\parindent}{0mm}



\begin{tabularx}{\linewidth}{@{}l@{ }r@{\,\,}l@{\,\,}l@{}X@{}}
\multicolumn{5}{@{}l@{}}{Hvis en addend minker med 1, så minker summen med 1:}\\
  Det betyr at\hspace{-3.5mm} & $5+2$ & $=$ & $7$, &\\
                  & $5+1$ & $=$ & $6$, &\\
                  & $5+0$ & $=$ & $5$, &\\
                  & $5+(-1)$ & $=$ & $4$, &\\
                  & $5+(-2)$ & $=$ & ${\color{red}3}$, osv., & \raggedleft\arraybackslash 
                     så å legge til et negativt tall\\
\multicolumn{5}{@{}p{\linewidth}@{}}{\raggedright er det samme som å trekke fra samme tall med motsatt fortegn:}\\
                 & $5+(-2)$ & $=$ & $5-(+2)=5-2={\color{red}3}$.&
\end{tabularx}

\end{document}
share|improve this answer
    
Yes! This is closer. I tagged the post with tabularx because it is a relevant package in my situation. Another method could be the tabbing environment. Your solution gets rid of the hardcoded lenghts in last column of the two tables, which is nice. There is another hardcoded length of 15.965mm left in the first column of the last table. In addition, I think there is too much code in my situation; Two instances of \makebox to make lines block justified (breaking hyphenation), and two instances of tables. The tabbing environment is a candidate, but it is not flexible enough. –  Jostein Trondal Mar 5 '13 at 6:35
    
the hard coded length in the second table is (I think?) to make it look like it aligns with the first which indicates it should all be one table, get rid of the two \makebox[\linewidth][s] and put them inside the table as `\multicolumn{5}{@{}l@{}}{.....}\` then everything line up automatically. –  David Carlisle Mar 5 '13 at 9:34
    
You are right about the alignment. I tried your suggestion now, but there are issues: The first line is not block justified, the last line pushes the text in the third last line, the second last line extends beyond the right edge, and the hyphenation is broken in two places. The hyphenation problem seems to be cronic for all attempts to put text in tables like I have done. !figure. –  Jostein Trondal Mar 5 '13 at 10:27
    
Using [s] to stretch a single line the full width of the text is almost never the right thing to do, that's why I suggested l in the multicolumns. You could add some negative skip at the end to cancel out the glue added by l but I wouldn't advise it. I can't understand your other comments "hyphenation is broken" isn't very specific. I added a one table version to the answer –  David Carlisle Mar 5 '13 at 11:45
    
I apologize for being unclear, and also if my problem seems to be a moving target.. I really appreciate your comments. I edited my original post to try to be more clear. –  Jostein Trondal Mar 5 '13 at 13:19
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.