I'm trying to reproduce this: enter image description here

I was able to reproduce everything but the frame below "John sleeps":

enter image description here

I first tried using gb4e, but I didn't find a solution. Now, my examples are written by hand, using the tabbing environment. The code follows:

\hspace{0.8em} \hspace{6em} \= \textit{Paul} \hspace{1.5em} \= 
\textit{thinks} \hspace{2.8em} \= \textit{that} \hspace{2.5em} \= 
\textit{John} \hspace{1.2em} \= \textit{sleeps}\\~\\
\hspace{0.8em}$(14)$ \hspace{5em} \= $n$ \hspace{2em} \= $s/(n)[n]$ 
\hspace{2em} \= $n/[s]$ \hspace{3em} \= $n$ \hspace{2em} \= $s/(n)$\\
\hspace{0.8em}$(15)$ \hspace{5em} \> $n$ \hspace{2em} \> $s/(n)[n]$ 
\hspace{2em} \> $n/[s]$ \hspace{4.8em} \= $s$\\
\hspace{0.8em}$(16)$ \hspace{5em} \> $n$ \hspace{2em} \> $s/(n)[n]$ 
\hspace{5em} \= $n$\\
\hspace{0.8em}$(17)$ \hspace{5em} \> \> \= \hspace{2.5em} $s.$

How can I make this frame around n and s/(n) of line 14 and s of line 15, just like the first image?

  • I added the linguistics tag and dropped mdframed. The question is not specifically about mdframed (yet), but it is about an example in linguistics, so that tag might be more useful for future visitors. – moewe May 20 '18 at 14:04
  • BTW: I really hope someone comes along and tells you how to do this with a more elegant method than a manual tabbing. The code is really hard to read and it looks like it would require quite a bit of manual intervention. – moewe May 20 '18 at 14:05
  • A bit of feedback if the answers helped you would be appreciated. If one of the answers worked for you, upvoting and accepting is a nice gesture to say thank you. If for some reason the answer did not work for you, leave a comment and explain why/how it did not work for you. – moewe May 28 '18 at 7:15

For what it's worth here is a solution using tabular instead of tabbing. It doesn't look exactly like your screenshot, but I'd say it comes close, the input seems more natural to me and there is no need for manual spacing, which requires trial and error and makes the source hard to read.

countedtabular is a tabular that automatically numbers its rows; the heading/first row is not numbered. You can use the optional argument to continue counting up from a different counter (for example if you use gb4e's exe environment).

In the example below all columns have a fixed size of 1.3cm, but you could vary the size or use d/c for automatic sizing.

Because you used math mode, all columns are automatically set in math mode. If you decide you don't like that you can switch to the non-math-mode column specifiers.

The box is drawn with TikZ using the fit library (see §52 Fitting Library of the PGF manual). You simply mark up the points that you want to be inside the rectangular box and the rest happens more or less automatically. You get a better result if you use a node-\tikzmark (see https://tex.stackexchange.com/a/235662/35864). Instead of typing the text that you want to have inside the box directly into the cell like s/(n), you give it a clever name (cell-sn) wrap it in \tikztextmark: \tikztextmark{cell-sn}{s/(n)}. Then you simply name cell-sn in \drawboxaroundnodes and it will be included in the box.


% new column formats 
% math mode built in
% fixed width
% see lockstep's answer in https://tex.stackexchange.com/a/12712/35864
% fixed width and math


% this implements a table with numbered rows
% if the optional argument is specified the counter of that name 
% is used to display the row numbers
             {}%                    only step the counter
             {\refstepcounter{#1}}% if it is not the row counter
          {}}R{22.77222pt}%<- hard-coded for gb4e, \labelwidth would work for normal enumerates

% https://tex.stackexchange.com/a/235662/35864
% https://tex.stackexchange.com/a/46496/35864
% set a node at position of text
% star: if star: no-autodetection of mode text typeset in text mode
%       no star:  surrounding text/math mode is detected and preserved 
% first argument: internal name of the node
% second argument: text
% e.g.: \tikztextmark{nodefoo}{Hullo} typesets "Hullo"
% the position can then be called with nodefoo

  \tikz[overlay,remember picture,baseline]\node [anchor=base] (#1)

% automatically draw a box around the given coordinates
% optional argument to change the style and other settings
% mandatory argument takes a list of coordinates
  \begin{tikzpicture}[overlay,remember picture]
  \node[draw=black, thick, inner sep=0pt, fit=#2, #1] {};

\ex Hallo
\ex Bye

\ex Hallo
\ex Tschüss

% compare and contrast the third and fourth row for different placement of the text
% compare and contrast the first and second row for the box anchors
&n & s/(n)[n] & n/[s] & n & s/(n)\\
&n & s/(n)[n] & n/[s] & \multicolumn{2}{d}{s}\\
&n & s/(n)[n] & \multicolumn{3}{d}{n}\\

&n & s/(n)[n] & n/[s] & \tikztextmark{cell-n}{n} & \tikztextmark{cell-sn}{s/(n)}\\
&n & s/(n)[n] & n/[s] & \multicolumn{2}{c}{\tikztextmark{cell-s}{s}}\\
&n & s/(n)[n] & \multicolumn{2}{d}{n}\\
% draw the box: give all coordinates in round brackets
\drawboxaroundnodes{(cell-sn) (cell-s) (cell-n)}

\ex Hoi
\ex Doei


enter image description here


TikZ is usually a good way to go to draw frames, here is the code I have used:


\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
    \tikz[overlay,remember picture]{
      ($(#2)+(-0.5em,2.0ex)$) rectangle

\hspace{0.8em} \hspace{6em} \= \textit{Paul} \hspace{1.5em} \= 
\textit{thinks} \hspace{2.8em} \= \textit{that} \hspace{2.5em} \= 
\textit{John} \hspace{1.2em} \= \textit{sleeps}\\~\\
\hspace{0.8em}$(14)$     \hspace{5em} \= $n$ \hspace{2em} \= $s/(n)[n]$ 
\hspace{2em} \= $n/[s]$ \hspace{3em} \= \tikzmark{top left 1} $n$\hspace{2em} \= $s/(n)$\\
\hspace{0.8em}$(15)$     \hspace{5em} \> $n$ \hspace{2em} \> $s/(n)[n]$ \hspace{2em} \> $n/[s]$ \hspace{4.8em} \= $s$ \hspace{20pt}\tikzmark{bottom right 1} \\
\hspace{0.8em}$(16)$     \hspace{5em} \> $n$ \hspace{2em} \> $s/(n)[n]$ 
\hspace{5em} \= $n$\\
\hspace{0.8em}$(17)$ \hspace{5em} \> \> \= \hspace{2.5em} $s.$

\DrawBox[thin, black]{top left 1}{bottom right 1}


enter image description here

The code I have used comes from this post. You can do more adjusting regarding the size of the frame, the color, etc... The idea is to position Tikzmarks in the table and then draw the frame around them as an overlay.

Hope it helps.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.