Canvas scaler and canvas width tablets.

I have a game that works great on mobiles and scales perfectly however for tablets it scales too wide. I tried adding some code to the canvas to limit it’s width but I am guessing the canvas scaler is overriding this. Is there anyway to limit the canvas width and have it appear in the middle of the screen on tablets so that the aspect ratio is preserved

public void resizer()
    {
        RectTransform objectRectTransform = gameObject.GetComponent<RectTransform>();
        float testheight = objectRectTransform.rect.height / objectRectTransform.rect.width;
        if (testheight < 1.7) {
            gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2 (70, 100);

        }
    }

use panels. you can set up panels pretty well and arrange them automatically, too. Be creative with them and you will find a nice solution that works. You can combine them with “layout-group”-components, too.