Referring to the body below, I would expect ~\ref{atts}
to produce Table 1, but instead, it gives just 1.
What is the issue here?
cross-referencingtables
Referring to the body below, I would expect ~\ref{atts}
to produce Table 1, but instead, it gives just 1.
What is the issue here?
Related to your MWE you can use the following:
\documentclass{article}
\makeatletter
\def\@firstoftwo@second#1#2{%
\def\temp##1.##2\@nil{##2}%
\temp#1\@nil}
\newcommand\sref[1]{%
\expandafter\@setref\csname r@#1\endcsname\@firstoftwo@second{#1}%
}
\makeatother
\begin{document}
\section{This is my section}
For further information see
\begin{tabular}{ll}
\verb+\sref{subsecone}+ & \sref{subsecone} \\
\verb+\sref{subsectwo}+ & \sref{subsectwo} \\
\verb+\sref{subsecthree}+ & \sref{subsecthree} \\
\end{tabular} within this section.
\subsection{One}\label{subsecone}
\subsection{Two}\label{subsectwo}
\subsection{Three}\label{subsecthree}
\end{document}
Some explanation.
The standard reference are saved in the aux-file in the following form:
\newlabel{subsectwo}{{1.2}{1}}
You can see that \newlabel
is a command with two mandatory argument. The first argument is the label name and the second argument has two other groups inside. The first group is the numbering scheme and the second group shows the page.
So you want to extract the first group of the second mandatory argument and then you want to extract the second part of the number.
With the command \@firstoftwo@second
you take the first group of the second argument of \newlabel
and due to it's defintion you extract your requested number.
LaTeX is brilliant and unparalleled in its field; but it's not magical. It typesets the table it's given; it can't know that you don't intend that table to extend past the margins unless you tell it so.
To control the overall width of a table, you can use tabularx
; its documentation is clear and complete, but the bottom line is you can change your column specifier to X
, and that column will stretch or shrink to allow the table to fit. In your table, columns 1, 3, and 4 seem to be the issues; so:
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\begin{table}[h]
\begin{tabularx}{\linewidth}{X|lXXXXXX}
\hline
sssssssss/sssss ss ssssssssss & sssssssss & ssssssss & ssssssss & sssssssssss & ssssssssss & sssssssss ssss sssssssss ssssssssss & sssssssss ssss sssssssss ssssssssssss \\ \hline
sssss ssssssssssss & sss & sss & sssssssss, ssssssssssss & sssssssss sssssss, sssssss & ssssss & & \\
ssssssssss ssssssssssss & sss & ss & sssssssss & ssssss ssssss & ssssss & & \\
ssssssss ssssssss & ss & sss & sssssssss, sssssssss sssssssssss & ssssssssssss, sssssssss & ssssss & & \\
ssss sssss & sss & sss & sssss, ssssssssss sssssss, ssssss ssssssss & ssssssssssss & sssssss & & \\
ssss & ss & sss & sssssss ssssss, sssssssss ssssssss & sssssssss & sssssss & & \\
sss & ss & sss & ssssssss ssssssssss & sssss sssssssss & sssssss & & \\
ssssss ssssss & ss & sss & ssssssss ssssssssss & sssssssss ss sssss sssssss & sssssss & &
\end{tabularx}
\end{table}
\end{document}
Now, your table still doesn't look very good; since there are very few word breaks, it's impossible for LaTeX to select good break points for the columns. But this should give you the idea.
You can also consider setting your table in landscape mode (see the lscape
package), or reducing the size of the text, though in the latter case you should be careful you're not making a stylistic mistake.
Also, please include a minimal working example in your question, that people can simply copy, paste, and compile, complete with \documentclass
and the rest; this makes it much easier for people to help you. A quick search will reveal more information about this.
Best Answer
You have to use some package that knows what you are referring. I suggest
cleveref
:For details, refer to the documentation -- execute
texdoc cleveref
from command prompt.