# Formatting new environment with borders

I have defined myself a new environment as below:

\newenvironment{myquote}{\list{}{\leftmargin=0.3in\rightmargin=0.3in}\item[]}{\endlist}


What I would like to do here is to be able to format this by adding borders. all borders needs to be solid but the left border needs to be thicker.

What is the way?

-
Use mdframed. It allows for breaking across pages as well. –  Werner Nov 11 '11 at 18:35
ok, it is nice but not what I want. Is there some way to specify borders like we do with css. I know it is so wrong to reference css here but it is kind of nice to be that flexible. –  tugberk Nov 11 '11 at 18:44
@MarcoDaniel it was a typo. if you can refresh the page you will see that it was corrected by cmhughes. –  tugberk Nov 11 '11 at 18:47
@tugberk: mdframed doesn't support css style. You can use \mdfdefinestyle to define your own style. At the moment I have no separate line specification implemented. But with the framemethod=default it should be very simple. –  Marco Daniel Nov 11 '11 at 18:52
@MarcoDaniel no, that's not what I meant. I am not looking for a css support here. I am looking for something similar to that. If you can provide me sample, that would be fine. I am now going through the documentation of your package mdframed. –  tugberk Nov 11 '11 at 18:56
show 1 more comment

Here a solution with mdframed. You have two new keys: addleftlinewidth and addleftlinecolor to modify the additional setting:

\documentclass{article}
\usepackage{showframe}
\usepackage[framemethod=default]{mdframed}
\makeatletter
}

\preto\md@frame@leftline@single{%
\rule[-\dp\@tempboxa-\mdf@innerbottommargin@length%
\ifbool{mdf@bottomline}{-\mdf@middlelinewidth@length}{}]%
+\ifbool{mdf@bottomline}{\mdf@middlelinewidth@length}{0pt}
+\ifbool{mdf@topline}{\mdf@middlelinewidth@length}{0pt}}%
\hspace*{\mdf@middlelinewidth@length}}%
}%
\makeatother
\mdfdefinestyle{cssstyle}{linecolor=blue,linewidth=2pt,%
skipbelow=\topskip,skipabove=\topskip}

\newmdenv[style=cssstyle]{myquote}

\usepackage{lipsum}

\begin{document}

\lipsum[2]
\end{myquote}

Text

\lipsum[3]
\end{myquote}
\end{document}


At the moment only the single frame is supported.

-
this is a cool solution. I am looking for a gray border but I guess it is not so difficult to change. Also, is there any support inside you package for margin and padding? –  tugberk Nov 11 '11 at 19:45
I tried the code it didn't compile. I gives bunch of errors. I am using lots of packages and I am guessing they are not playing nice together. –  tugberk Nov 11 '11 at 19:58
well I get bunch of them. here is the first one: "option clash for package mdframed. \mkaetletter" I mean really I am the only one who is bothered with this. How hard can it be to put borders. IMO, something missing at the core level for TeX or I am Really looking at the WRONG direction. –  tugberk Nov 11 '11 at 20:47
–  Marco Daniel Nov 11 '11 at 21:22

You could use the adjustbox package to add a frame around it, then clip some sides of the frame to make them thinner.

I removed the quote and replaced it with a centered minipage, because that's simpler to handle with adjustbox. However, it can't be broken across pages.

There is no direct CSS-like way to define frames or borders. Some of the adjustbox keys allow for 1, 2 or 4 arguments like some CSS settings do (see the manual for more), but that's it. In LaTeX you basically always have to box the content in question and then draw lines around it dependent on its size. If you want anything special like a frame only on one side (or that one thicker) than you can also use a drawing package like TikZ or PSTricks to do this. Actually the mentioned mdframe package does uses on of these.

\documentclass{article}

\newenvironment{myquote}{%
\par\smallskip\par\noindent
minipage=\linewidth-0.6in, % to get your 2x0.3in border
fbox=2pt, % 2pt frame all around
Clip=0pt 1pt 1pt 1pt, % remove 1pt of the bottom, top and right frame
center % center the whole thing (around \linewidth)
}\bgroup
}{%
\egroup
\par\smallskip\par
}

\usepackage{lipsum}
\begin{document}

\lipsum[1]
\begin{myquote}
\lipsum[2]
\end{myquote}
\lipsum[3]

\end{document}


-
That's a good example. Thanks. With LaTeX we can nearly do anything we want logical but we always need other stuff around. For example, here I also need padding inside the framed box and margins around it. I know this is another topic. I am just expressing I haven't been able to find the core logic of TeX so far. Maybe I am looking at the wrong direction. –  tugberk Nov 11 '11 at 19:18
Margins and padding can be added using the margin key. Just use it before the fbox for padding and after for a margin. –  Martin Scharrer Nov 11 '11 at 19:21

if you do not need a pagebreak its really simple:

\documentclass{article}
\usepackage{array,xcolor,lipsum}
\newenvironment{myquote}
{\par\medskip\noindent\hspace*{0.3in}
\tabular{!{\color{blue!40}%
\vrule width 5pt}p{\dimexpr\linewidth-0.6in-2\tabcolsep-5pt\relax}|}\hline}
{\\\hline\endtabular\par\medskip}

\begin{document}
\lipsum[1]
\begin{myquote}
\lipsum[1]
foo bar baz
\end{myquote}
\lipsum[1]
\end{document}


-

Using mdframed is probably the way to go if you need to be able to cross page boundaries. Instead of thicker lines, you could also use tikz with shadows to highlight the desired edges. Here I have adapted the solution from New command for a height-flexible rect. Not only can you can adjust the values of xshift to get a thicker shadow, but the full power available of tikz is available to customize as you desire:

\documentclass[border=5pt]{standalone}
\usepackage{calc}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage{tikz}

text width=0.97\linewidth,
draw=black,
shade, top color=white, bottom color=white,
top color=black,
bottom color=black,
shadow yshift=-0.5pt,% 0pt removes shading at bottom
},
rectangle,
]

\newcommand{\myquote}[2][]{%
\noindent%
\begin{tikzpicture}%
\node [shadedbox, #1] (box) {#2};%
\end{tikzpicture}%
}

\newcommand{\ShortLoremIpsum}{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam turpis turpis, rutrum vel facilisis nec, scelerisque ut nisi.

Proin et elit sapien. Ut non ante tellus. Pellentesque et tempus metus. Phasellus sit amet est nisl, a varius elit. Nunc nunc magna, molestie sit amet fermentum a, facilisis at urna.
}%

\begin{document}

\myquote{\ShortLoremIpsum}

\myquote[bottom color=yellow!10]{\ShortLoremIpsum}

\myquote[rounded corners=5pt, line width=1.0pt, draw=blue]{\ShortLoremIpsum}

\myquote[text width=0.6\linewidth, top color=red!10, densely dotted]{\ShortLoremIpsum}
\end{document}

-