Text FormattingHow to put a box around multiple lines.

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
mojin
Posts: 4
Joined: Sun Mar 01, 2009 10:45 am

How to put a box around multiple lines.

Post by mojin »

I just want to put a box around multiple lines. But I couldn't find a proper way to do it. Here is what I did,

Code: Select all

 \fbox{
 $\begin{array}{l}
 Given\; the\; vectors\; {\bf p}\; and\; {\bf n}\; as\; input,\; and\;
 the\;
 function\; {\sl f},\\ find\; the\; scalar\; \lambda\; that\; minimizes\; f({\bf
 p}+\lambda {\bf n}). \\
 Replace\; {\bf p}\; by\; {\bf p} + \lambda {\bf
 n}.\; Replace\; {\bf n}\; by\; \lambda {\bf n}. \end{array}$
 }

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

How to put a box around multiple lines.

Post by phi »

This code is horrible, but it puts all three lines in a box, so what is your problem?
Here is a better code that produces similar output:

Code: Select all

\documentclass{article}
\let\vec\mathbf

\begin{document}
\fbox{%
	\parbox{0.8\linewidth}{%
		Given the vectors $\vec p$ and $\vec n$ as input, and the function $f$,
		find the scalar $\lambda$ that minimizes $f(\vec p + \lambda \vec n)$.
		Replace $\vec p$ by $\vec p + \lambda \vec n$.
		Replace $\vec n$ by $\lambda \vec n$.%
	}%
}
\end{document}
Post Reply