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 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?

share|improve this question
4  
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

5 Answers 5

up vote 7 down vote accepted

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
\mdf@do@lengthoption{addleftlinewidth==\z@}
\newcommand*\mdf@addleftlinecolor{\mdf@linecolor}
\define@key{mdf}{addleftlinecolor}[\mdf@linecolor]{%
  \def\mdf@addleftlinecolor{#1}%
}
\mdfsetup{settings={\addtolength{\mdf@leftmargin@length}{\mdf@addleftlinewidth@length}}}

\preto\md@frame@leftline@single{%
           \llap{\color{\mdf@addleftlinecolor}%{\mdf@middlelinecolor}%
               \rule[-\dp\@tempboxa-\mdf@innerbottommargin@length%
                        \ifbool{mdf@bottomline}{-\mdf@middlelinewidth@length}{}]%
                    {\mdf@addleftlinewidth@length}{\mdfboundingboxheight%
                         +\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,%
                          addleftlinewidth=6pt,addleftlinecolor=red,
                         skipbelow=\topskip,skipabove=\topskip}

\newmdenv[style=cssstyle]{myquote}

\usepackage{lipsum}

\begin{document}

\begin{myquote}[addleftlinewidth=6pt]
\lipsum[2]
\end{myquote}

Text

\begin{myquote}[addleftlinewidth=4pt,addleftlinecolor=yellow]
\lipsum[3]
\end{myquote}
\end{document}

enter image description here

At the moment only the single frame is supported.

share|improve this answer
    
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
    
let us continue this discussion in chat –  Marco Daniel Nov 11 '11 at 21:22
add comment

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}

\usepackage{adjustbox}

\newenvironment{myquote}{%
    \par\smallskip\par\noindent
    \adjustbox{%
        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}

Result

share|improve this answer
    
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
add comment

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}

enter image description here

share|improve this answer
add comment

A tcolorbox example was missing. So, just for completion, next code shows how to produce a breakable gray bordered box with thicker left side.

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}

\newtcolorbox{mybox}{%
     enhanced, breakable, arc=0pt, outer arc=0pt, leftrule=2mm, colback=white,
}

\begin{document}
\lipsum[1]
\begin{mybox}
\lipsum[2-6]
\end{mybox}
\lipsum[7]
\begin{mybox}
\lipsum[8]
\end{mybox}
\end{document}

enter image description here

share|improve this answer
add comment

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:

enter image description here

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

\tikzstyle{shadedbox} = [
  text width=0.97\linewidth,
  draw=black,
  shade, top color=white, bottom color=white,
  drop shadow={
    top color=black,
    bottom color=black,
    shadow xshift=-1.5pt,% add shading on left
    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}
share|improve this answer
add 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.