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.

Is there an equivalent in LaTeX to the CSS border-top, border-bottom, border-right properties?

I would like to underline and overline text with with a border on the right, not simply underline or overline it. So instead of a simple underline the text would get underlined/overlined with a border on the right.

Here's an example of what I would like to do (in CSS): http://accent.u-biq.org/english.html

I saw PDFs with such annotation before, so I'm pretty sure it can be done.

(Four tags for Google search: Japanese pitch accent annotation)

share|improve this question
    
Note that this is usually called a frame not border with LaTeX. It is possible to have variants of \fbox, \frame etc. which only draw the frame rule on one or two specific sides, but I don't know any packages which provide such macros. In general you shouldn't compare HTML/CSS and LaTeX, because both use different concepts. –  Martin Scharrer May 12 '12 at 12:58
1  
Frames in the mdframed package seem to have boolean attributes topline, bottomline, leftline and rightline. These might do the job for you. (I trust the link to the page drawn with css was only to show a picture of what you want.) See ctan.math.utah.edu/ctan/tex-archive/macros/latex/contrib/… –  Ethan Bolker May 12 '12 at 14:03
    
A little more looking found this SE answer, which does indeed use mdframed. How to choose which sides of the border to draw in a framebox? –  Ethan Bolker May 12 '12 at 14:28

2 Answers 2

As I already answered to the cross-post on LaTeX-Community.org: a quick and easy way would be to define a TikZ matrix for the characters, where each character is a node which can be referred to, for drawing such a path.

For example:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
  \matrix (m) [matrix of nodes]{
    A & B & C & D & E\\};
  \draw (m-1-1.north west) -- (m-1-1.north east) -- (m-1-1.south east)
    -- (m-1-2.south west) -- (m-1-2.south east) -- (m-1-2.north east)
    -- (m-1-5.north east);
\end{tikzpicture}
\end{document}

path around symbols

share|improve this answer
    
+1 for TikZ. Using tikz-timing would be overkill. –  Martin Scharrer May 12 '12 at 14:57
    
Thank you for the answer! –  Phil May 13 '12 at 8:03

It is possible to have variants of \fbox, \frame etc. which only draw the frame rule on one or two specific sides, but I don't know any packages which provide such macros.

I took the standard LaTeX \fbox definition and added color support and an optional argument which can be used to select the sides with a frame: l left, b bottom, r right and t top. The line thickness can be changed using the \fboxrule length and the separation between the content and the frame using \fboxsep.

\documentclass{article}

\usepackage{xcolor}

\makeatletter

\newcommand\cfbox[3][lbrt]{%
  \begingroup
  \leavevmode
  \setbox\@tempboxa\hbox{%
    \color@begingroup
      \kern\fboxsep{#3}\kern\fboxsep
    \color@endgroup
  }%
  \@tempdima\fboxrule
  \advance\@tempdima\fboxsep
  \advance\@tempdima\dp\@tempboxa
  \hbox{%
    \hskip-.5\fboxrule
    \lower\@tempdima\hbox{%
      \vbox{%
        \in@{t}{#1}%
        \ifin@
            {\color{#2}%
            \hrule\@height\fboxrule
            }%
        \fi
        \hbox{%
          \in@{l}{#1}%
          \ifin@
            {\color{#2}%
            \vrule\@width\fboxrule
            }%
          \fi
          \vbox{%
            \vskip\fboxsep
            \box\@tempboxa
            \vskip\fboxsep}%
          \in@{r}{#1}%
          \ifin@
            {\color{#2}%
            \vrule\@width\fboxrule
            }%
          \fi
        }%
        \in@{b}{#1}%
        \ifin@
          {\color{#2}%
          \hrule\@height\fboxrule
          }%
        \fi
      }%
    }%
    \hskip-.5\fboxrule
  }%
  \endgroup
}

\makeatother

\begin{document}

\cfbox[l]{red}{A}%
\cfbox[b]{red}{B}%
\cfbox[r]{red}{C}%
\cfbox[t]{red}{D}%

\bigskip


\setlength{\fboxsep}{.2ex}
\cfbox[b]{red}{AB}%
\cfbox[ltr]{red}{C}%
\cfbox[b]{red}{D}%

\end{document}

Result

share|improve this answer
    
PS: I'm using the helpful macro \in@ from the LaTeX kernel here. See macros2e and source2e. –  Martin Scharrer May 12 '12 at 15:39
    
Thank you for that! I prefer this method to the one by Stefan, as I can have a script automate my text easier. –  Phil May 13 '12 at 7:59
    
@Phil: No problem, using TikZ is indeed easier for this specific case. I posted this solution more as a programming exercise. –  Martin Scharrer May 13 '12 at 8:22

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.