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.

I have a figure with a long list of predicates connected with \wedge, here is the code:

\begin{figure}[h]               
    \small{     
    $
    Defined\_in(subject\_state, concrete\_subject) \wedge Defined\_in (observer\_state, concrete\_observer) \wedge
    Defined\_in(attach, subject) \wedge Defined\_in(detach, subject) \wedge Defined\_in(notify, subject) \wedge ... it continues ...
    $
    }
    \caption{Caption text}
    \label{fig:myfig}
\end{figure}

the problem is that the output produced by pdflatex is rather ugly:

ugly output

what I would like is to align it all to left, which I think will look better. If I use \[ and \] instead of $, latex places all the content on one line which overlaps from the page. I would like to avoid manual inserting of new lines with \\, and rather let latex to break it up into lines and align it to left.

share|improve this question

2 Answers 2

up vote 5 down vote accepted
% In the preamble
\usepackage{amsmath}
\newcommand{\func}{\textit}
\newcommand{\var}{\textit}

% In the document
\begin{figure}
\small
\begin{align*}
&\func{Defined\_in}(\var{subject\_state}, \var{concrete\_subject}) \wedge {}\\
&\func{Defined\_in}(\var{observer\_state}, \var{concrete\_observer}) \wedge {}\\
&\func{Defined\_in}(\var{attach}, \var{subject}) \wedge {}\\
&\func{Defined\_in}(\var{detach}, \var{subject}) \wedge {}\\
&\func{Defined\_in}(\var{notify}, \var{subject}) \wedge {}\\
...
\end{align*}
\caption{Caption text}
\label{fig:myfig}
\end{figure}

It's way better to use \textit{Defined\_in} instead of simply Defined\_in in math mode as you will see immediately. I propose to distinguish functions from variables, so that you may change their formatting just by modifying the definition of \func or \var.

Just erase {}\\& if you want to merge two lines.

A "beginner's definition" for \func would be

\newcommand{\func}[1]{\textit{#1}}

but definitions such as this one waste time reading the argument twice.

share|improve this answer
    
Thank you. I thought there might be a way to let latex break it up in lines, but apparently, this is not possible. Besides the need for manual new-lines, your solution works for me. –  Steves May 23 '11 at 10:08

You seem to be writing code; if this is the case, then perhaps you should consider using the listings package; refer to the package documentation to learn all the possibilities it offers. Here's a very simple configuration for your example code:

\documentclass{article}
\usepackage{listings}

\lstset{escapeinside=||,%
  linewidth=\textwidth,%
  basicstyle=\small,%
  breaklines%
}

\begin{document}

\begin{lstlisting}[frame=single,captionpos=top,caption={Caption text},label=myalg]               
Defined_in(subject_state,concrete_subject) |$\wedge$|
Defined_in(observer_state,concrete_observer) |$\wedge$|
Defined_in(attach,subject) |$\wedge$| Defined_in(detach,subject) |$\wedge$|
Defined_in(notify,subject) |$\wedge$|
\end{lstlisting}

\end{document}

EDIT: If you want automatic line-breaking in dsiplayed math, you could give the breqn package a try; here's a little example using the definitions of egreg's answer:

\documentclass{article}
\usepackage{breqn}

\newcommand{\func}{\textit}
\newcommand{\var}{\textit}

\begin{document}

\begin{figure}
\small
\begin{dmath*}
\func{Defined\_in}(\var{subject\_state}, \var{concrete\_subject}) \wedge\func{Defined\_in}(\var{observer\_state}, \var{concrete\_observer}) \wedge\func{Defined\_in}(\var{attach}, \var{subject}) \wedge\func{Defined\_in}(\var{detach}, \var{subject}) \wedge\func{Defined\_in}(\var{notify}, \var{subject}) \wedge ...
\end{dmath*}
\caption{Caption text}
\label{fig:myfig}
\end{figure}

\end{document}

The result:

share|improve this answer
    
Tank you for your answer, I am aware of listings package, but this is supposed to be really mathematical formula, although about programming :-) Just for curiosity: it's taken from the Design Patterns Formalization Techniques book. –  Steves May 23 '11 at 10:11
    
@Steves: I've updated my answer; I included an example that gives automatic line-breaking. –  Gonzalo Medina May 23 '11 at 13:50

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.