在 Tikz 上缩放图片

在 Tikz 上缩放图片

我正在尝试缩放我的 TikZ 图片,以便它能适合文档的第一页。我已经尝试在[scale=.8]写好的地方添加\begin{tikzpicture},但显然不起作用。有人知道可以解决这个问题的命令吗?

谢谢

\documentclass{article}
\usepackage{geometry}

\usepackage{geometry}
\usepackage{tikz}
\usepackage{amsmath}
\definecolor{mygreen}{HTML}{29AB87}
\definecolor{myred}{HTML}{9F0101}
\definecolor{myblue}{HTML}{1C4966}
\definecolor{mygray}{HTML}{a9a9a9}
\usepackage{mdframed}
\usetikzlibrary{shapes.multipart,shapes, shapes.geometric}


\begin{document}
    
\section*{Modeling the database}
    
Use the provided SQL script ($movie_rentals.sql$) to create the movie rentals database, and then:\\[2ex]

1. Inspect the database and describe its tables using the following notation:
    \begin{align*}
&\begin{alignedat}{1}
table1(column1, column2, column3, ...)
\end{alignedat}
\\
&\begin{alignedat}{1}
column2 : FK(table2)
\end{alignedat}
\end{align*}
    
\begin{mdframed}[backgroundcolor=mygray!12,rightline=false,leftline=false, bottomline=false, topline=false]
    
\textbf{Resolution}\\[3ex]

\noindent
movie(\underline{movie\_id}, title, release\_year,length,rating,category)\\[2ex]

\noindent
actor(\underline{actor\_id},first\_name, last\_name)\\[2ex]

\noindent
movie\_actor(\underline{movie\_id}, \underline{actor\_id})\\
\indent \indent movie\_id: FK(movie)\\
\indent \indent actor\_id: FK(actor)\\[2ex]

\noindent
customer(\underline{customer\_id}, first\_name, last\_name, adress, postal\_code, district, city, country)\\[2ex]

\noindent
rental(\underline{rental\_id}, customer\_id, movie\_id, rental\_date, amount)\\
\indent \indent customer\_id: FK(customer)\\
\indent \indent movie\_id: FK(movie)\\
\end{mdframed}
\vspace{3ex}

2. Draw an E-R diagram for the database, by reverse engineering from the existing tables.

\begin{mdframed}[backgroundcolor=mygray!12,rightline=false,leftline=false, bottomline=false, topline=false]
\hspace{-3ex}
\begin{tikzpicture}
[
roundnode/.style={circle, draw=myblue, fill=myblue!50, very thick, minimum size=7mm},
terminator/.style={ellipse, draw=myred, very thick, minimum size=7mm},
squarednode/.style={rectangle, draw=myred, , very thick, minimum size=5mm},
decision/.style={diamond, draw=myblue , very thick, minimum size=5mm},
square/.style={regular polygon,regular polygon sides=4},
]

%Nodes
%NodesMovie
\node at ( 1,0) [squarednode] (movie) {movie};

\node at ( 3,1) [terminator] (movieid) {\underline{movie\_id}};
\node at ( 1.3,1.7) [terminator] (title) {title};
\node at ( 0.2,3) [terminator] (releaseyear) {release\_year};
\node at ( -1.7,2) [terminator] (length) {length};
\node at ( -1.7,0.8) [terminator] (rating) {rating};
\node at ( -1.7,-0.3) [terminator] (category) {category};

%NodesRental
\node at ( 1,-4) [squarednode] (rental) {rental};

\node at ( 2.5,-5.3) [terminator] (rentalid) {\underline{rental\_id}};
\node at ( -0.2,-4.8) [terminator] (rentaldate) {rental\_date};
\node at ( -1,-3.6) [terminator] (amount) {amount};

%NodesCustomer
\node at ( 8,-4) [squarednode] (customer) {customer};

\node at ( 10,-3.4) [terminator] (city) {city};
\node at ( 7,-2.7) [terminator] (customerid) {\underline{customer\_id}};
\node at ( 6.3,-5) [terminator] (firstname) {first\_name};
\node at ( 8,-6) [terminator] (lastname) {last\_name};
\node at ( 10.2,-6.1) [terminator] (adress) {adress};
\node at ( 10.9,-5.2) [terminator] (postalcode) {postal\_code};
\node at ( 11.2,-4.2) [terminator] (country) {country};
\node at ( 9.5,-2.5) [terminator] (district) {district};

%NodesActor
\node at ( 8,0) [squarednode] (actor) {actor};
\node at ( 8,1.4) [terminator] (actorid) {\underline{actor\_id}};
\node at ( 9.86,0.7) [terminator] (firstnamea) {first\_name};
\node at ( 9.9,-0.8) [terminator] (lastnamea) {last\_name};


\node at ( 5,0) [decision] (movieactor) {movie\_actor};
\node at ( 1,-2) [decision] (rented) {rented};
\node at ( 4,-4) [decision] (rents) {rents};

%lines 

%LinesMovie
\draw [black!75,  thick] (movieid) -- (movie);
\draw [black!75,  thick] (title) -- (movie);
\draw [black!75,  thick] (releaseyear) -- (movie);
\draw [black!75,  thick] (length) -- (movie);
\draw [black!75,  thick] (rating) -- (movie);
\draw [black!75,  thick] (category) -- (movie);

%LinesRental
\draw [black!75,  thick] (rental) -- (rentalid);
\draw [black!75,  thick] (rental) -- (rentaldate);
\draw [black!75,  thick] (rental) -- (amount);

%LinesCustomer
\draw [black!75,  thick] (customer) -- (city);
\draw [black!75,  thick] (customer) -- (customerid);
\draw [black!75,  thick] (customer) -- (firstname);
\draw [black!75,  thick] (customer) -- (lastname);
\draw [black!75,  thick] (customer) -- (adress);
\draw [black!75,  thick] (customer) -- (postalcode);
\draw [black!75,  thick] (customer) -- (country);
\draw [black!75,  thick] (customer) -- (district);

%LinesActor
\draw [black!75,  thick] (actor) -- (actorid);
\draw [black!75,  thick] (actor) -- (firstnamea);
\draw [black!75,  thick] (actor) -- (lastnamea);

%LinesBetweenIdentities

\draw[double, black!75, ultra thick] (movie) -- (movieactor);

\draw [ black!75, ultra thick] (movieactor) -- (actor);

\draw [<-, black!75, ultra thick] (movie) -- (rented);

\draw [ black!75, ultra thick] (rented) -- (rental);

\draw [ black!75, ultra thick] (rental) -- (rents);

\draw [->, black!75, ultra thick] (rents) -- (customer);
\end{tikzpicture}
\end{mdframed}


\end{document} 

答案1

解决方案取自这里mdframed根据要应用的因素扩展整个环境

\documentclass{article}
\usepackage{geometry}

\usepackage{geometry}
\usepackage{tikz}
\usepackage{amsmath}
\definecolor{mygreen}{HTML}{29AB87}
\definecolor{myred}{HTML}{9F0101}
\definecolor{myblue}{HTML}{1C4966}
\definecolor{mygray}{HTML}{a9a9a9}
\usepackage{mdframed}
\usepackage{adjustbox}
\usetikzlibrary{shapes.multipart,shapes, shapes.geometric}


\begin{document}
    
    \section*{Modeling the database}
    
    Use the provided SQL script ($movie_rentals.sql$) to create the movie rentals database, and then:\\[2ex]
    
    1. Inspect the database and describe its tables using the following notation:
    \begin{align*}
        &\begin{alignedat}{1}
            table1(column1, column2, column3, ...)
        \end{alignedat}
        \\
        &\begin{alignedat}{1}
            column2 : FK(table2)
        \end{alignedat}
    \end{align*}
    
    \adjustbox{varwidth=\linewidth, scale=0.8}{%
        \begin{mdframed}[backgroundcolor=mygray!12,rightline=false,leftline=false, bottomline=false, topline=false]
            
            \textbf{Resolution}\\[3ex]
            
            \noindent
            movie(\underline{movie\_id}, title, release\_year,length,rating,category)\\[2ex]
            
            \noindent
            actor(\underline{actor\_id},first\_name, last\_name)\\[2ex]
            
            \noindent
            movie\_actor(\underline{movie\_id}, \underline{actor\_id})\\
            \indent \indent movie\_id: FK(movie)\\
            \indent \indent actor\_id: FK(actor)\\[2ex]
            
            \noindent
            customer(\underline{customer\_id}, first\_name, last\_name, adress, postal\_code, district, city, country)\\[2ex]
            
            \noindent
            rental(\underline{rental\_id}, customer\_id, movie\_id, rental\_date, amount)\\
            \indent \indent customer\_id: FK(customer)\\
            \indent \indent movie\_id: FK(movie)\\
        \end{mdframed}
    }%
    \vspace{3ex}
    
    2. Draw an E-R diagram for the database, by reverse engineering from the existing tables.
    
    \adjustbox{varwidth=\linewidth, scale=0.8}{%
        \begin{mdframed}[backgroundcolor=mygray!12,rightline=false,leftline=false, bottomline=false, topline=false]
            \hspace{-3ex}
            \begin{tikzpicture}
                [
                roundnode/.style={circle, draw=myblue, fill=myblue!50, very thick, minimum size=7mm},
                terminator/.style={ellipse, draw=myred, very thick, minimum size=7mm},
                squarednode/.style={rectangle, draw=myred, , very thick, minimum size=5mm},
                decision/.style={diamond, draw=myblue , very thick, minimum size=5mm},
                square/.style={regular polygon,regular polygon sides=4},
                ]
                
                %Nodes
                %NodesMovie
                \node at ( 1,0) [squarednode] (movie) {movie};
                
                \node at ( 3,1) [terminator] (movieid) {\underline{movie\_id}};
                \node at ( 1.3,1.7) [terminator] (title) {title};
                \node at ( 0.2,3) [terminator] (releaseyear) {release\_year};
                \node at ( -1.7,2) [terminator] (length) {length};
                \node at ( -1.7,0.8) [terminator] (rating) {rating};
                \node at ( -1.7,-0.3) [terminator] (category) {category};
                
                %NodesRental
                \node at ( 1,-4) [squarednode] (rental) {rental};
                
                \node at ( 2.5,-5.3) [terminator] (rentalid) {\underline{rental\_id}};
                \node at ( -0.2,-4.8) [terminator] (rentaldate) {rental\_date};
                \node at ( -1,-3.6) [terminator] (amount) {amount};
                
                %NodesCustomer
                \node at ( 8,-4) [squarednode] (customer) {customer};
                
                \node at ( 10,-3.4) [terminator] (city) {city};
                \node at ( 7,-2.7) [terminator] (customerid) {\underline{customer\_id}};
                \node at ( 6.3,-5) [terminator] (firstname) {first\_name};
                \node at ( 8,-6) [terminator] (lastname) {last\_name};
                \node at ( 10.2,-6.1) [terminator] (adress) {adress};
                \node at ( 10.9,-5.2) [terminator] (postalcode) {postal\_code};
                \node at ( 11.2,-4.2) [terminator] (country) {country};
                \node at ( 9.5,-2.5) [terminator] (district) {district};
                
                %NodesActor
                \node at ( 8,0) [squarednode] (actor) {actor};
                \node at ( 8,1.4) [terminator] (actorid) {\underline{actor\_id}};
                \node at ( 9.86,0.7) [terminator] (firstnamea) {first\_name};
                \node at ( 9.9,-0.8) [terminator] (lastnamea) {last\_name};
                
                
                \node at ( 5,0) [decision] (movieactor) {movie\_actor};
                \node at ( 1,-2) [decision] (rented) {rented};
                \node at ( 4,-4) [decision] (rents) {rents};
                
                %lines 
                
                %LinesMovie
                \draw [black!75,  thick] (movieid) -- (movie);
                \draw [black!75,  thick] (title) -- (movie);
                \draw [black!75,  thick] (releaseyear) -- (movie);
                \draw [black!75,  thick] (length) -- (movie);
                \draw [black!75,  thick] (rating) -- (movie);
                \draw [black!75,  thick] (category) -- (movie);
                
                %LinesRental
                \draw [black!75,  thick] (rental) -- (rentalid);
                \draw [black!75,  thick] (rental) -- (rentaldate);
                \draw [black!75,  thick] (rental) -- (amount);
                
                %LinesCustomer
                \draw [black!75,  thick] (customer) -- (city);
                \draw [black!75,  thick] (customer) -- (customerid);
                \draw [black!75,  thick] (customer) -- (firstname);
                \draw [black!75,  thick] (customer) -- (lastname);
                \draw [black!75,  thick] (customer) -- (adress);
                \draw [black!75,  thick] (customer) -- (postalcode);
                \draw [black!75,  thick] (customer) -- (country);
                \draw [black!75,  thick] (customer) -- (district);
                
                %LinesActor
                \draw [black!75,  thick] (actor) -- (actorid);
                \draw [black!75,  thick] (actor) -- (firstnamea);
                \draw [black!75,  thick] (actor) -- (lastnamea);
                
                %LinesBetweenIdentities
                
                \draw[double, black!75, ultra thick] (movie) -- (movieactor);
                
                \draw [ black!75, ultra thick] (movieactor) -- (actor);
                
                \draw [<-, black!75, ultra thick] (movie) -- (rented);
                
                \draw [ black!75, ultra thick] (rented) -- (rental);
                
                \draw [ black!75, ultra thick] (rental) -- (rents);
                
                \draw [->, black!75, ultra thick] (rents) -- (customer);
            \end{tikzpicture}
        \end{mdframed}
    }%
    
\end{document} 

两个框架的系数均为 0.8,因此可以将其全部放在一页上。

\adjustbox{varwidth=\linewidth, scale=0.8}{...}

在此处输入图片描述

相关内容