3

I'm writing a paper, but in the process, I encounter a problems : when I drawing a map with the following codes

\documentclass{article}
    \usepackage{amsmath,amssymb,booktabs}
    \begin{document} 
    \begin{figure}
    \[
    \begin{array}{@{}l@{}c@{}l@{}}
    \toprule
     \hat{A}  &&  \hat{B}  \\
     (a,A=g^a)  &&  (b,B=g^b)  \\
      x\in_R[1,q-1] ,\quad  X=g^{H_1(x,a)}   \\
    & \xrightarrow{\textstyle  ID_A, Cert_A,  X } \\
    &&  y\in_R [1,q-1] ,\quad  Y=g^{H_1(y,b)}  \\ 
    & \xleftarrow {\textstyle  ID_B,Cert_B, Y  } \\
      K=H_2(Y^a,B^{H_1(x,a)},Y^{H_1(x,a)},\hat{A},\hat{B})  \\
    &&  K=H_2(A^{H_1(y,b)},X^b,X^{H_1(y,b)},\hat{A},\hat{B})   \\
    \bottomrule
    \end{array}
    \]
     \caption{title}
     \end{figure}
    \end{document}

I find that this it beyond the margin. Just like this enter image description here

You can see very obviously that it beyond the margin. Both changing the font size and rotating the map won't get it to adapt to my article(I tried these two ways). who can help me?

Werner
  • 603,163
Nax
  • 1,411
  • 5
  • 16
  • 19
  • 1
    Your code does not produce any overfull warnings. – Sigur Apr 17 '14 at 15:15
  • 1
    Do you mean, that your array is printed partially into page margins? This is not the case if I compile your document. –  Apr 17 '14 at 15:15
  • I think you might want to try producing parts of the map independently before assembling them altogether. I suspect you have too many linebreaks (these guys \\)... – Alex Nelson Apr 17 '14 at 15:40
  • You should rewrite the array to show the same concept but in a different way. You can resize the entire thing to make it fit within the margins (which may be sufficient): \resizebox{\linewidth}{!}{$\begin{array}...\end{array}$} or some techniques from Center figure that is wider than \textwidth. – Werner Apr 18 '14 at 00:18
  • @Werner : not it doesn't work, when I compile, the figure disappeared – Nax Apr 18 '14 at 00:35
  • @Alex: Also remove the surrounding display math environment. Did you add \usepackage{graphicx} to your document preamble? – Werner Apr 18 '14 at 03:12
  • @Werner : Thank you, it works. \resizebox{\linewidth}{!}{$\begin{array}...\end{array}$} reduce the size to make it flush to each side. But if I want to make it smaller, what can I do ?(P.s. I think you can arrange your comments into a single answer) – Nax Apr 18 '14 at 03:32

1 Answers1

2

If your contents is too wide, you can resize-to-fit using

% In your document preamble
\usepackage{graphicx}% http://ctan.org/pkg/graphicx

% ...

\begin{figure}
  \resizebox{\linewidth}{!}{$
    \begin{array}{..}
      %...
    \end{array}
  $}
  \caption{...}
\end{figure}

This will resize everything, including making the font smaller. You can also centre the contents and leave it as-is using

\begin{figure}
  \makebox[\linewidth]{$
    \begin{array}{..}
      %...
    \end{array}
  $}%
  \caption{...}
\end{figure}

This would be similar to the methods in Center figure that is wider than \textwidth.

Werner
  • 603,163