5

(second post) The previous answer works fine for the tables I have, except for big tables that I need to rotate has shown in the next code. I played with the first two parameters of the solution proposed (the '2' of 'wide-2' and the '.3' of '\hspace{.3\tabcolsep)', but did not manage to find the proper setting of these parameters. The code with a rotated matrix is given below.

\documentclass{book}

\usepackage{graphicx}
\usepackage{eqparbox}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}

\newcommand{\PTSConstraint}[1]{\constraint{$g$\_$f$\_{#1}}}
\newcommand{\Pre}[1]{\ensuremath\overrightarrow{#1}}
\newcommand{\Suf}[1]{\ensuremath\overleftarrow{#1}}
\newcommand{\Neither}{\AGG{\Pre{C},\Suf{C}}}
\newcommand{\Creates}{\Fea(\Pre{D},\Suf{D},\Con)}
\newcommand{\ExtendLeft}{\Fea(\Pre{C},\Pre{D},\Suf{D},\Con)}
\newcommand{\ExtendRight}{\Fea(\Suf{C},\Pre{D},\Suf{D},\Con)}
\newcommand{\Extendboth}{\Fea(\Pre{C},\Suf{C},\Pre{D},\Suf{D},\Con)}
\newcommand{\ExtendbothHat}{\Fea(\Pre{C},\Suf{C},\Pre{D},\Suf{D},\ConHat)}
\newcommand{\Agg}{g}
\newcommand{\AGG}[1]{\phi_\Agg(#1)}
\newcommand{\Fea}{\ensuremath{\phi_f}} 
\newcommand{\Con}{\delta_f^{i+1}}
\newcommand{\ConHat}{\hat{\delta}_f^{i+1}}

\newcommand{\AnnotatedCreatesChar}{$\diamond$}
\newcommand{\AnnotatedExtendLeftChar}{$\blacktriangleright$}
\newcommand{\AnnotatedExtendRightChar}{$\blacktriangleleft$}
\newcommand{\AnnotatedExtendbothChar}{$\square$}
\newcommand{\AnnotatedExtendbothHatChar}{$\blacksquare$}

\newcommand{\AnnotatedCreates}{\eqmakebox[wide-2]{$\Creates$}\rlap{\hspace{.3\tabcolsep}\raisebox{.6\normalbaselineskip}[0pt][0pt]{\scriptsize \AnnotatedCreatesChar}}}
\newcommand{\AnnotatedExtendLeft}{\eqmakebox[wide-2]{$\ExtendLeft$}\rlap{\hspace{.3\tabcolsep}\raisebox{.6\normalbaselineskip}[0pt][0pt]{\scriptsize \AnnotatedExtendLeftChar}}}
\newcommand{\AnnotatedExtendRight}{\eqmakebox[wide-2]{$\ExtendRight$}\rlap{\hspace{.3\tabcolsep}\raisebox{.6\normalbaselineskip}[0pt][0pt]{\scriptsize \AnnotatedExtendRightChar}}}
\newcommand{\AnnotatedExtendboth}{\eqmakebox[wide-2]{$\Extendboth$}\rlap{\hspace{.3\tabcolsep}\raisebox{.6\normalbaselineskip}[0pt][0pt]{\scriptsize \AnnotatedExtendbothChar}}}
\newcommand{\AnnotatedExtendbothHat}{\eqmakebox[wide-2]{$\ExtendbothHat$}\rlap{\hspace{.3\tabcolsep}\raisebox{.6\normalbaselineskip}[0pt][0pt]{\scriptsize \AnnotatedExtendbothHatChar}}}

\begin{table}[h]
  \setlength{\tabcolsep}{3pt}
  \centering
  \renewcommand{\arraystretch}{1.6}
\scalebox{0.85}{\rotatebox{90}{
\begin{tabular}{c|c|c|c|c|c|c|c|}
\multicolumn{1}{c}{} & \multicolumn{1}{c}{$s$} & \multicolumn{1}{c}{$a$} & \multicolumn{1}{c}{$b$} & \multicolumn{1}{c}{$c$} & \multicolumn{1}{c}{$d$} & \multicolumn{1}{c}{$e$} & \multicolumn{1}{c}{$f$} \\
 \cline{2-8}
{$s$} & $\Neither$ & $\Neither$ & $\Neither$ & $\Neither$ & $\Neither$ & $\Neither$ & $\Neither$ \\
 \cline{2-8}
{$a$} & $\Neither$ & $\Neither$ & $\Neither$ & \AnnotatedExtendRight & $\Neither$ & \AnnotatedCreates & $\Neither$ \\
\cline{2-8}
{$b$} & $\Neither$ & $\Neither$ & \AnnotatedCreates & $\Neither$ & \AnnotatedCreates & $\Neither$ & \AnnotatedExtendRight \\
\cline{2-8}
{$c$} & $\Neither$ & \AnnotatedExtendLeft & $\Neither$ & \AnnotatedExtendboth & $\Neither$ & \AnnotatedExtendLeft & $\Neither$ \\
\cline{2-8}
{$d$} & $\Neither$ & $\Neither$ & \AnnotatedCreates & $\Neither$ & $\Neither$ & $\Neither$ & \AnnotatedExtendRight \\
\cline{2-8}
{$e$} & $\Neither$ & \AnnotatedCreates & $\Neither$ & \AnnotatedExtendRight & $\Neither$ & \AnnotatedCreates & $\Neither$ \\
\cline{2-8}
{$f$} & $\Neither$ & $\Neither$ & \AnnotatedExtendLeft & $\Neither$ & \AnnotatedExtendLeft & $\Neither$ & \AnnotatedExtendboth \\
\cline{2-8}
\end{tabular}
}}
\caption{Parametrised glue matrix for any zigzag constraint}
\end{table}

\end{document}

(initial post) Given the following table, I would like to annotate some cells without changing the cell size; the annotation should be in the upper rightmost corner of some cell and shoud consist of one single tiny uppercase letter (or one tiny symbol).

If I start writing the symbol in a standard way, I will get two problems: (1) the cell size changes, (2) the symbol is not in the upper righmost corner.

\documentclass{book}

\newcommand{\Pre}[1]{\ensuremath\overrightarrow{#1}}
\newcommand{\Suf}[1]{\ensuremath\overleftarrow{#1}}
\newcommand{\Neither}{\AGG{\Pre{C},\Suf{C}}}
\newcommand{\Creates}{\Fea(\Pre{D},\Suf{D},\Con)}
\newcommand{\Agg}{g}
\newcommand{\AGG}[1]{\phi_\Agg(#1)}
\newcommand{\Fea}{\ensuremath{\phi_f}} 
\newcommand{\Con}{\delta_f^{i+1}}

\begin{document}

\begin{table}[h]
  \setlength{\tabcolsep}{10pt}
  \centering
  \renewcommand{\arraystretch}{1.6}
\begin{tabular}{c|c|c|c|}
\multicolumn{1}{c}{} & \multicolumn{1}{c}{$s$} & \multicolumn{1}{c}{$r$} & \multicolumn{1}{c}{$t$} \\
\cline{2-4}
{$s$} & $\Neither$ & $\Neither$ & $\Neither$ \\
\cline{2-4}
{$r$} & $\Neither$ & $\Neither$ &  $\Creates$ \\
\cline{2-4}
{$t$} & $\Neither$ & $\Creates$ & $\Creates$ \\
\cline{2-4}
\end{tabular}
\caption{Parametrised glue matrix}
\end{table}

\end{document}
  • If you do the table in TikZ, this is easy, but maybe that's overkill? – cfr Dec 21 '17 at 0:13
  • Why do you use \multicolumn{1}{c}{} when the cells are already c specified? – cfr Dec 21 '17 at 0:14
  • I did not want to use TikZ if possible, because TikZ is a bottleneck when compiling a file containing a lot of figures (even if one uses the externalized option in a way that takes advantage of all the cores of your machine). – Nicolas Beldiceanu Dec 21 '17 at 20:02
  • As I say, it is overkill here. Werner's solution should avoid that. Externalisation doesn't use multiple cores. What it does is avoids recompiling pictures which haven't changed. So it should only be a bottleneck when you've changed the code of a picture - and it should only affect that picture. However, if you add or remove pictures, you get additional runs unless you've named your pictures. This is a significant issue with the library, but is not so difficult to workaround to avoid the defaults. – cfr Dec 22 '17 at 0:39
  • I know externalisation avoid recompiling the pictures which haven't changed. But the first compilation that use externalisation of a document containing thousand of Tikz pictures can takes hours (rather than a few minutes) when using one single core. But you can organise your figures in mutiples files and use a makefile to externalise figures in parallel. And many of my pictures are produced by a program, so that I have to rebuild all of them: therefore quite often, externalisation save me time only in the 2nd and 3rd time of a LaTeX compilation. – Nicolas Beldiceanu Dec 22 '17 at 7:08
4

Here is an idea: We store the content of the widest element in a box and then store the to-be-superscripted-cell in a box of the same width. This will not affect the table/column width. Then one can place the superscript in a zero-width box and move it into place.

enter image description here

\documentclass{article}

\usepackage{eqparbox}

\newcommand{\Pre}[1]{\overrightarrow{#1}}
\newcommand{\Suf}[1]{\overleftarrow{#1}}
\newcommand{\Neither}{\AGG{\Pre{C}, \Suf{C}}}
\newcommand{\Creates}{\Fea(\Pre{D}, \Suf{D}, \Con)}
\newcommand{\Agg}{g}
\newcommand{\AGG}[1]{\phi_\Agg(#1)}
\newcommand{\Fea}{\phi_f}
\newcommand{\Con}{\delta_f^{i + 1}}

\begin{document}

\begin{table}
  \setlength{\tabcolsep}{10pt}
  \centering
  \renewcommand{\arraystretch}{1.6}
  \begin{tabular}{ c | c | c | c | }
    \multicolumn{1}{c}{} & \multicolumn{1}{c}{$s$} & \multicolumn{1}{c}{$r$} & \multicolumn{1}{c}{$t$} \\
    \cline{2-4}
    $s$ & $\Neither$ & \eqmakebox[wide-2]{$\Neither$}\rlap{\textsuperscript{2}} & $\Neither$ \\
    \cline{2-4}
    $r$ & $\Neither$ & $\Neither$ & $\Creates$ \\
    \cline{2-4}
    $t$ & $\Neither$ & \eqmakebox[wide-2]{$\Creates$} & $\Creates$ \\
    \cline{2-4}
  \end{tabular}
  \caption{Parametrised glue matrix}
\end{table}

\end{document}

Of course, more movement of the \textsuperscript{2} is possible to perfectly position it, like

enter image description here

% ...
\eqmakebox[wide-2]{$\Neither$}%
  \rlap{\hspace{.5\tabcolsep}\raisebox{.6\normalbaselineskip}[0pt][0pt]{\scriptsize 2}}
% ...
1

Here is a solution that satisfies the requirement that the cell size is unchanged. However, you may need to adjust the distances yshift and right of by hand.

EDIT: If you don't want to use TikZ and/or do not like to adjust things by hand, you may use \newcommand{\MarkCell}[2]{\hfill#1\hspace*{3pt}\makebox[-3pt][l]{${}^{#2}$}}.

\documentclass{book}

\newcommand{\Pre}[1]{\ensuremath\overrightarrow{#1}}
\newcommand{\Suf}[1]{\ensuremath\overleftarrow{#1}}
\newcommand{\Neither}{\AGG{\Pre{C},\Suf{C}}}
\newcommand{\Creates}{\Fea(\Pre{D},\Suf{D},\Con)}
\newcommand{\Agg}{g}
\newcommand{\AGG}[1]{\phi_\Agg(#1)}
\newcommand{\Fea}{\ensuremath{\phi_f}} 
\newcommand{\Con}{\delta_f^{i+1}}
\usepackage{tikz}
\usetikzlibrary{positioning}
% from https://tex.stackexchange.com/questions/339526/confusion-over-use-of-tikzmark
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\newcommand{\MarkCell}[2]{\hfill#1\hspace*{3pt}\makebox[-3pt][l]{${}^{#2}$}}
\begin{document}

\begin{table}[h]
  \setlength{\tabcolsep}{10pt}
  \centering
  \renewcommand{\arraystretch}{1.6}
\begin{tabular}{c|c|c|c|}
\multicolumn{1}{c}{} & \multicolumn{1}{c}{$s$} & \multicolumn{1}{c}{$r$} & \multicolumn{1}{c}{$t$} \\
\cline{2-4}
{$s$} & $\Neither$ & $\Neither$\tikzmark{pfft} & $\Neither$ \\
\cline{2-4}
{$r$} & $\Neither$ & \hfill$\Neither$\hfill \hspace*{3pt}\makebox[-3pt][l]{${}^3$} &  $\Creates$ \\
\cline{2-4}
{$t$} & \MarkCell{$\Neither$}{4} & $\Creates$ & \MarkCell{$\Creates$}{5} \\
\cline{2-4}
\end{tabular}
\caption{Parametrised glue matrix}
\end{table}
\tikz[overlay,remember picture]{\node[anchor=south,right=3mm of pfft,yshift=3mm]{${\scriptstyle 2}$};} 
\end{document}

enter image description here

  • I’m not sure the example will typeset that table. Wrong copy-paste? – egreg Dec 22 '17 at 10:07
  • @egreg It does, but you're right: there was some unnecessary stuff after \end{document}. Grazie! – user121799 Dec 22 '17 at 12:28

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.